Preserve discovery failures for damaged checkouts
This commit is contained in:
@@ -55,7 +55,7 @@ func TestDiscoverRepositoryRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoRepositoryDiagnostic(t *testing.T) {
|
||||
func TestNoRepositoryBoundary(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
message string
|
||||
want bool
|
||||
@@ -65,12 +65,63 @@ func TestNoRepositoryDiagnostic(t *testing.T) {
|
||||
{"fatal: not a git repository: '/bad'", false},
|
||||
{"fatal: detected dubious ownership in repository", false},
|
||||
} {
|
||||
if got := noRepositoryDiagnostic(tc.message); got != tc.want {
|
||||
if _, got := noRepositoryBoundary(tc.message); got != tc.want {
|
||||
t.Errorf("diagnostic %q = %t", tc.message, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverRepositoryRootHonorsDiscoveryBoundaries(t *testing.T) {
|
||||
repo := newRemoteFixture(t)
|
||||
child := filepath.Join(repo.work, "child")
|
||||
if err := os.Mkdir(child, 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
alias := filepath.Join(t.TempDir(), "alias")
|
||||
if err := os.Symlink(repo.work, alias); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Remove(filepath.Join(repo.work, ".git", "HEAD")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
name, directory, ceiling string
|
||||
standalone bool
|
||||
}{
|
||||
{"damaged ancestor", child, "", false},
|
||||
{"excluded ancestor", child, repo.work, true},
|
||||
{"physical ceiling alias", child, alias, true},
|
||||
{"literal ceiling alias", child, string(os.PathListSeparator) + alias, false},
|
||||
{"ceiling includes current directory", repo.work, repo.work, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Setenv("GIT_CEILING_DIRECTORIES", tc.ceiling)
|
||||
_, found, err := DiscoverRepositoryRoot(t.Context(), tc.directory)
|
||||
if tc.standalone {
|
||||
if err != nil || found {
|
||||
t.Fatalf("excluded checkout: found %t, error %v", found, err)
|
||||
}
|
||||
} else {
|
||||
var exitErr *exec.ExitError
|
||||
if found || !errors.As(err, &exitErr) || exitErr.ExitCode() != 128 {
|
||||
t.Fatalf("damaged checkout: found %t, error %v", found, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
bin := t.TempDir()
|
||||
script := "#!/bin/sh\nprintf 'fatal: not a git repository (or any parent up to mount point %s)\\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\\n' \"$DISCOVERY_BOUNDARY\" >&2\nexit 128\n"
|
||||
if err := os.WriteFile(filepath.Join(bin, "git"), []byte(script), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Setenv("PATH", bin)
|
||||
t.Setenv("GIT_CEILING_DIRECTORIES", "")
|
||||
t.Setenv("DISCOVERY_BOUNDARY", repo.work)
|
||||
if _, found, err := DiscoverRepositoryRoot(t.Context(), child); err != nil || found {
|
||||
t.Fatalf("filesystem boundary: found %t, error %v", found, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverRepositoryRootFailures(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
bin := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user