Limit readiness scans to selected package inputs

This commit is contained in:
2026-12-06 03:33:52 +00:00
parent 3f7dd4b2e5
commit 4b515404a8
6 changed files with 193 additions and 24 deletions

View File

@@ -386,6 +386,30 @@ func ReadTree(ctx context.Context, repositoryDir, commit string) ([]TreeEntry, e
return entries, nil
}
// ReadTreeDirectory lists immediate entries of a resolved repository-relative
// directory in a captured commit. Entry paths remain repository-relative.
func ReadTreeDirectory(ctx context.Context, repositoryDir, commit, directory string) ([]TreeEntry, error) {
if !validObjectID(commit) {
return nil, fmt.Errorf("invalid commit object ID %q", commit)
}
if directory == "" || path.IsAbs(directory) || path.Clean(directory) != directory || directory == ".." || strings.HasPrefix(directory, "../") {
return nil, fmt.Errorf("invalid committed directory %q", directory)
}
args := []string{"--literal-pathspecs", "ls-tree", "-z", "--full-tree", commit}
if directory != "." {
args = append(args, "--", directory+"/")
}
output, err := readLocalObjects(ctx, repositoryDir, nil, args...)
if err != nil {
return nil, fmt.Errorf("enumerate committed directory %q: %w", directory, err)
}
entries, err := parseTreeEntries(output)
if err != nil {
return nil, fmt.Errorf("parse committed directory %q: %w", directory, err)
}
return entries, nil
}
// ReadBlob reads the bytes for a Git blob object ID without consulting the
// worktree.
func ReadBlob(ctx context.Context, repositoryDir, objectID string) ([]byte, error) {