alibaba/open-code-review · error
git ls-files (tracked): %w
Error message
git ls-files (tracked): %w
What it means
listFilesViaGit runs `git -c core.quotepath=false ls-files -z` to list tracked files. Any failure of that git invocation is wrapped as 'git ls-files (tracked): ...'. It indicates git itself failed, not that files are missing.
Source
Thrown at internal/scan/provider.go:170
// with the simpler in-process gitignore handling (root .gitignore + the
// internal ExcludedDirs blocklist).
func (p *Provider) listFiles(ctx context.Context) ([]string, error) {
if p.isGitRepo(ctx) {
return p.listFilesViaGit(ctx)
}
return p.listFilesViaWalk(ctx)
}
// isGitRepo reports whether p.repoDir is inside a git working tree.
func (p *Provider) isGitRepo(ctx context.Context) bool {
cmd := exec.CommandContext(ctx, "git", "-C", p.repoDir, "rev-parse", "--git-dir")
return cmd.Run() == nil
}
func (p *Provider) listFilesViaGit(ctx context.Context) ([]string, error) {
tracked, err := p.gitLs(ctx, "-z")
if err != nil {
return nil, fmt.Errorf("git ls-files (tracked): %w", err)
}
untracked, err := p.gitLs(ctx, "-z", "--others", "--exclude-standard")
if err != nil {
return nil, fmt.Errorf("git ls-files (untracked): %w", err)
}
seen := make(map[string]struct{}, len(tracked)+len(untracked))
all := make([]string, 0, len(tracked)+len(untracked))
for _, f := range append(tracked, untracked...) {
if f == "" {
continue
}
if _, ok := seen[f]; ok {
continue
}
seen[f] = struct{}{}
all = append(all, f)
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Run `git ls-files` manually in the repo to see the raw git error.
- Ensure the git binary is installed and on PATH.
- Rebuild a corrupt index with `git read-tree HEAD` (or re-clone).
- Check for context timeout and raise it if the repo is very large.
Defensive patterns
Strategy: try-catch
Validate before calling
cmd := exec.Command("git", "-C", repoDir, "ls-files", "-z")
if err := cmd.Run(); err != nil {
return fmt.Errorf("git ls-files will fail: %w", err)
} Type guard
func isGitLsError(err error) bool {
return err != nil && strings.Contains(err.Error(), "git ls-files (tracked)")
} Try / catch
files, err := provider.Enumerate(ctx)
if err != nil {
var gitErr *exec.ExitError
if errors.As(err, &gitErr) && strings.Contains(err.Error(), "tracked") {
// inspect git stderr, possibly repair index
return fmt.Errorf("repair git repo, then retry: %w", err)
}
return err
} Prevention
- Keep the git index healthy; run `git status` before automated scans.
- Ensure git is installed and on PATH in CI images.
- Avoid context cancellation during file listing; budget enough time for large repos.
- Don't tamper with HOME/core config that git needs mid-run.
When it happens
Trigger: p.gitLs(ctx, "-z") returns a non-nil error — git exits non-zero (not a repo despite the earlier check, corrupt index, git binary missing) or the context is canceled while git runs.
Common situations: Corrupt .git/index, git not installed or not on PATH, HOME unset causing git config errors, disk full, or context deadline exceeded on huge repos.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/8178e5a3dc65541a.
Report an issue: GitHub.