{"record":{"id":"8178e5a3dc65541a","repo":"alibaba/open-code-review","slug":"git-ls-files-tracked-w","errorCode":null,"errorMessage":"git ls-files (tracked): %w","messagePattern":"git ls-files \\(tracked\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/scan/provider.go","lineNumber":170,"sourceCode":"// with the simpler in-process gitignore handling (root .gitignore + the\n// internal ExcludedDirs blocklist).\nfunc (p *Provider) listFiles(ctx context.Context) ([]string, error) {\n\tif p.isGitRepo(ctx) {\n\t\treturn p.listFilesViaGit(ctx)\n\t}\n\treturn p.listFilesViaWalk(ctx)\n}\n\n// isGitRepo reports whether p.repoDir is inside a git working tree.\nfunc (p *Provider) isGitRepo(ctx context.Context) bool {\n\tcmd := exec.CommandContext(ctx, \"git\", \"-C\", p.repoDir, \"rev-parse\", \"--git-dir\")\n\treturn cmd.Run() == nil\n}\n\nfunc (p *Provider) listFilesViaGit(ctx context.Context) ([]string, error) {\n\ttracked, err := p.gitLs(ctx, \"-z\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"git ls-files (tracked): %w\", err)\n\t}\n\tuntracked, err := p.gitLs(ctx, \"-z\", \"--others\", \"--exclude-standard\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"git ls-files (untracked): %w\", err)\n\t}\n\n\tseen := make(map[string]struct{}, len(tracked)+len(untracked))\n\tall := make([]string, 0, len(tracked)+len(untracked))\n\tfor _, f := range append(tracked, untracked...) {\n\t\tif f == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tif _, ok := seen[f]; ok {\n\t\t\tcontinue\n\t\t}\n\t\tseen[f] = struct{}{}\n\t\tall = append(all, f)\n\t}","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/scan/provider.go#L152-L188","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"cmd := exec.Command(\"git\", \"-C\", repoDir, \"ls-files\", \"-z\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"git ls-files will fail: %w\", err)\n}","typeGuard":"func isGitLsError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"git ls-files (tracked)\")\n}","tryCatchPattern":"files, err := provider.Enumerate(ctx)\nif err != nil {\n    var gitErr *exec.ExitError\n    if errors.As(err, &gitErr) && strings.Contains(err.Error(), \"tracked\") {\n        // inspect git stderr, possibly repair index\n        return fmt.Errorf(\"repair git repo, then retry: %w\", err)\n    }\n    return err\n}","preventionTips":["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."],"tags":["git","file-enumeration","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}