This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1053 from Minnozz/fix-1051
Don't assume every git repository has a HEAD
- Loading branch information
Showing
2 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,6 +524,63 @@ func testHgSourceInteractions(t *testing.T) { | |
<-donech | ||
} | ||
|
||
func TestGitSourceListVersionsNoHEAD(t *testing.T) { | ||
t.Parallel() | ||
|
||
requiresBins(t, "git") | ||
|
||
h := test.NewHelper(t) | ||
defer h.Cleanup() | ||
h.TempDir("smcache") | ||
cpath := h.Path("smcache") | ||
h.TempDir("repo") | ||
repoPath := h.Path("repo") | ||
|
||
// Create test repo with a single commit on the master branch | ||
h.RunGit(repoPath, "init") | ||
h.RunGit(repoPath, "config", "--local", "user.email", "[email protected]") | ||
h.RunGit(repoPath, "config", "--local", "user.name", "Test author") | ||
h.RunGit(repoPath, "commit", "--allow-empty", `--message="Initial commit"`) | ||
|
||
// Make HEAD point at a nonexistent branch (deleting it is not allowed) | ||
// The `git ls-remote` that listVersions() calls will not return a HEAD ref | ||
// because it points at a nonexistent branch | ||
h.RunGit(repoPath, "symbolic-ref", "HEAD", "refs/heads/nonexistent") | ||
|
||
un := "file://" + filepath.ToSlash(repoPath) | ||
u, err := url.Parse(un) | ||
if err != nil { | ||
t.Fatalf("Error parsing URL %s: %s", un, err) | ||
} | ||
mb := maybeGitSource{u} | ||
|
||
ctx := context.Background() | ||
superv := newSupervisor(ctx) | ||
isrc, _, err := mb.try(ctx, cpath, newMemoryCache(), superv) | ||
if err != nil { | ||
t.Fatalf("Unexpected error while setting up gitSource for test repo: %s", err) | ||
} | ||
|
||
err = isrc.initLocal(ctx) | ||
if err != nil { | ||
t.Fatalf("Error on cloning git repo: %s", err) | ||
} | ||
|
||
src, ok := isrc.(*gitSource) | ||
if !ok { | ||
t.Fatalf("Expected a gitSource, got a %T", isrc) | ||
} | ||
|
||
pvlist, err := src.listVersions(ctx) | ||
if err != nil { | ||
t.Fatalf("Unexpected error getting version pairs from git repo: %s", err) | ||
} | ||
|
||
if len(pvlist) != 1 { | ||
t.Errorf("Unexpected version pair length:\n\t(GOT): %d\n\t(WNT): %d", len(pvlist), 1) | ||
} | ||
} | ||
|
||
func Test_bzrSource_exportRevisionTo_removeVcsFiles(t *testing.T) { | ||
t.Parallel() | ||
|
||
|