diff --git a/internal/fetcher/fetcher.go b/internal/fetcher/fetcher.go index 7b6844c..99e8202 100644 --- a/internal/fetcher/fetcher.go +++ b/internal/fetcher/fetcher.go @@ -47,8 +47,8 @@ func Fetch(ctx context.Context, cacheRoot, name, repo, commit, version, path, ds if !ok { return time.Time{}, clierr.New(clierr.CodeConfig, - fmt.Sprintf("path %q of dependency %q not found at commit %.12s", path, name, commit), - "an empty or missing path is almost always a mistyped `path` — check the manifest", + fmt.Sprintf("subdir %q of dependency %q not found at commit %.12s", path, name, commit), + "an empty or missing subdir is almost always a typo — check the manifest", ) } } @@ -74,8 +74,8 @@ func Fetch(ctx context.Context, cacheRoot, name, repo, commit, version, path, ds if info, err := os.Stat(treeRoot); err != nil || !info.IsDir() { return time.Time{}, clierr.New(clierr.CodeConfig, - fmt.Sprintf("path %q of dependency %q not found at commit %.12s", path, name, commit), - "an empty or missing path is almost always a mistyped `path` — check the manifest", + fmt.Sprintf("subdir %q of dependency %q is not a directory at commit %.12s", path, name, commit), + "a subdir must point at a directory in the dependency repo — check the manifest", ) } } diff --git a/internal/fetcher/fetcher_test.go b/internal/fetcher/fetcher_test.go index 0c757c6..5293c78 100644 --- a/internal/fetcher/fetcher_test.go +++ b/internal/fetcher/fetcher_test.go @@ -171,6 +171,21 @@ func TestFetch_missingPath(t *testing.T) { } } +func TestFetch_pathIsFile(t *testing.T) { + t.Parallel() + + r := gittest.New(t) + r.WriteFile("a.txt", "x\n") + sha := r.Commit("first") + + // ls-tree reports the blob, so the pre-checkout existence check passes and + // the "not a directory" branch after checkout must catch it. + _, err := fetcher.Fetch(t.Context(), cacheRoot(t), depName, r.URL(), sha, "", "a.txt", fetchDst(t)) + if got := clierr.ExitCode(err); got != int(clierr.CodeConfig) { + t.Fatalf("exit code = %d, want %d (error: %v)", got, clierr.CodeConfig, err) + } +} + func TestFetch_commitGone(t *testing.T) { t.Parallel() diff --git a/internal/hasher/hasher.go b/internal/hasher/hasher.go index e72a185..5a272c1 100644 --- a/internal/hasher/hasher.go +++ b/internal/hasher/hasher.go @@ -165,7 +165,7 @@ func HashTree(root string) (string, error) { if len(digests) == 0 { return "", clierr.New(clierr.CodeConfig, "the dependency tree contains no files", - "an empty dependency is almost always a mistyped `path` — check the manifest", + "an empty dependency is almost always a mistyped `subdir` — check the manifest", ) }