@@ -218,15 +218,31 @@ func testFetchBySHA(t *testing.T, keepGitDir bool) {
218
218
}
219
219
220
220
func TestFetchUnreferencedTagSha (t * testing.T ) {
221
- testFetchUnreferencedTagSha ( t , false )
221
+ testFetchUnreferencedRefSha ( t , "v1.2.3-special" , false )
222
222
}
223
223
224
224
func TestFetchUnreferencedTagShaKeepGitDir (t * testing.T ) {
225
- testFetchUnreferencedTagSha ( t , true )
225
+ testFetchUnreferencedRefSha ( t , "v1.2.3-special" , true )
226
226
}
227
227
228
- // testFetchUnreferencedTagSha tests fetching a SHA that points to a tag that is not reachable from any branch.
229
- func testFetchUnreferencedTagSha (t * testing.T , keepGitDir bool ) {
228
+ func TestFetchUnreferencedRefSha (t * testing.T ) {
229
+ testFetchUnreferencedRefSha (t , "refs/special" , false )
230
+ }
231
+
232
+ func TestFetchUnreferencedRefShaKeepGitDir (t * testing.T ) {
233
+ testFetchUnreferencedRefSha (t , "refs/special" , true )
234
+ }
235
+
236
+ func TestFetchUnadvertisedRefSha (t * testing.T ) {
237
+ testFetchUnreferencedRefSha (t , "refs/special~" , false )
238
+ }
239
+
240
+ func TestFetchUnadvertisedRefShaKeepGitDir (t * testing.T ) {
241
+ testFetchUnreferencedRefSha (t , "refs/special~" , true )
242
+ }
243
+
244
+ // testFetchUnreferencedRefSha tests fetching a SHA that points to a ref that is not reachable from any branch.
245
+ func testFetchUnreferencedRefSha (t * testing.T , ref string , keepGitDir bool ) {
230
246
if runtime .GOOS == "windows" {
231
247
t .Skip ("Depends on unimplemented containerd bind-mount support on Windows" )
232
248
}
@@ -239,7 +255,7 @@ func testFetchUnreferencedTagSha(t *testing.T, keepGitDir bool) {
239
255
240
256
repo := setupGitRepo (t )
241
257
242
- cmd := exec .Command ("git" , "rev-parse" , "v1.2.3-special" )
258
+ cmd := exec .Command ("git" , "rev-parse" , ref )
243
259
cmd .Dir = repo .mainPath
244
260
245
261
out , err := cmd .Output ()
@@ -691,6 +707,8 @@ func setupGitRepo(t *testing.T) gitRepoFixture {
691
707
// * (refs/heads/feature) withsub
692
708
// * feature
693
709
// * (HEAD -> refs/heads/master, tag: refs/tags/lightweight-tag) third
710
+ // | * ref only
711
+ // | * commit only
694
712
// | * (tag: refs/tags/v1.2.3-special) tagonly-leaf
695
713
// |/
696
714
// * (tag: refs/tags/v1.2.3) second
@@ -699,35 +717,53 @@ func setupGitRepo(t *testing.T) gitRepoFixture {
699
717
"git -c init.defaultBranch=master init" ,
700
718
"git config --local user.email test" ,
701
719
"git config --local user.name test" ,
720
+
702
721
"echo foo > abc" ,
703
722
"git add abc" ,
704
723
"git commit -m initial" ,
705
724
"git tag --no-sign a/v1.2.3" ,
725
+
706
726
"echo bar > def" ,
707
727
"mkdir subdir" ,
708
728
"echo subcontents > subdir/subfile" ,
709
729
"git add def subdir" ,
710
730
"git commit -m second" ,
711
731
"git tag -a -m \" this is an annotated tag\" v1.2.3" ,
732
+
712
733
"echo foo > bar" ,
713
734
"git add bar" ,
714
735
"git commit -m tagonly-leaf" ,
715
736
"git tag --no-sign v1.2.3-special" ,
737
+
738
+ "echo foo2 > bar2" ,
739
+ "git add bar2" ,
740
+ "git commit -m \" commit only\" " ,
741
+ "echo foo3 > bar3" ,
742
+ "git add bar3" ,
743
+ "git commit -m \" ref only\" " ,
744
+ "git update-ref refs/special $(git rev-parse HEAD)" ,
745
+
716
746
// switch master back to v1.2.3
717
747
"git checkout -B master v1.2.3" ,
748
+
718
749
"echo sbb > foo13" ,
719
750
"git add foo13" ,
720
751
"git commit -m third" ,
721
752
"git tag --no-sign lightweight-tag" ,
753
+
722
754
"git checkout -B feature" ,
755
+
723
756
"echo baz > ghi" ,
724
757
"git add ghi" ,
725
758
"git commit -m feature" ,
726
759
"git update-ref refs/test $(git rev-parse HEAD)" ,
760
+
727
761
"git submodule add " + fixture .subURL + " sub" ,
728
762
"git add -A" ,
729
763
"git commit -m withsub" ,
764
+
730
765
"git checkout master" ,
766
+
731
767
// "git log --oneline --graph --decorate=full --all",
732
768
)
733
769
return fixture
@@ -785,6 +821,7 @@ func runShell(t *testing.T, dir string, cmds ...string) {
785
821
cmd = exec .Command ("sh" , "-c" , args )
786
822
}
787
823
cmd .Dir = dir
824
+ // cmd.Stdout = os.Stdout
788
825
cmd .Stderr = os .Stderr
789
826
require .NoErrorf (t , cmd .Run (), "error running %v" , args )
790
827
}
0 commit comments