@@ -524,6 +524,63 @@ func testHgSourceInteractions(t *testing.T) {
524
524
<- donech
525
525
}
526
526
527
+ func TestGitSourceListVersionsNoHEAD (t * testing.T ) {
528
+ t .Parallel ()
529
+
530
+ requiresBins (t , "git" )
531
+
532
+ h := test .NewHelper (t )
533
+ defer h .Cleanup ()
534
+ h .TempDir ("smcache" )
535
+ cpath := h .Path ("smcache" )
536
+ h .TempDir ("repo" )
537
+ repoPath := h .Path ("repo" )
538
+
539
+ // Create test repo with a single commit on the master branch
540
+ h .RunGit (repoPath , "init" )
541
+ h .
RunGit (
repoPath ,
"config" ,
"--local" ,
"user.email" ,
"[email protected] " )
542
+ h .RunGit (repoPath , "config" , "--local" , "user.name" , "Test author" )
543
+ h .RunGit (repoPath , "commit" , "--allow-empty" , `--message="Initial commit"` )
544
+
545
+ // Make HEAD point at a nonexistent branch (deleting it is not allowed)
546
+ // The `git ls-remote` that listVersions() calls will not return a HEAD ref
547
+ // because it points at a nonexistent branch
548
+ h .RunGit (repoPath , "symbolic-ref" , "HEAD" , "refs/heads/nonexistent" )
549
+
550
+ un := "file://" + filepath .ToSlash (repoPath )
551
+ u , err := url .Parse (un )
552
+ if err != nil {
553
+ t .Fatalf ("Error parsing URL %s: %s" , un , err )
554
+ }
555
+ mb := maybeGitSource {u }
556
+
557
+ ctx := context .Background ()
558
+ superv := newSupervisor (ctx )
559
+ isrc , _ , err := mb .try (ctx , cpath , newMemoryCache (), superv )
560
+ if err != nil {
561
+ t .Fatalf ("Unexpected error while setting up gitSource for test repo: %s" , err )
562
+ }
563
+
564
+ err = isrc .initLocal (ctx )
565
+ if err != nil {
566
+ t .Fatalf ("Error on cloning git repo: %s" , err )
567
+ }
568
+
569
+ src , ok := isrc .(* gitSource )
570
+ if ! ok {
571
+ t .Fatalf ("Expected a gitSource, got a %T" , isrc )
572
+ }
573
+
574
+ pvlist , err := src .listVersions (ctx )
575
+ if err != nil {
576
+ t .Fatalf ("Unexpected error getting version pairs from git repo: %s" , err )
577
+ }
578
+
579
+ if len (pvlist ) != 1 {
580
+ t .Errorf ("Unexpected version pair length:\n \t (GOT): %d\n \t (WNT): %d" , len (pvlist ), 1 )
581
+ }
582
+ }
583
+
527
584
func Test_bzrSource_exportRevisionTo_removeVcsFiles (t * testing.T ) {
528
585
t .Parallel ()
529
586
0 commit comments