{"record":{"id":"c9447862dcae58e5","repo":"zed-industries/zed","slug":"git-ls-files-failed-in-with-status","errorCode":null,"errorMessage":"git ls-files failed in {} with status {}: {}","messagePattern":"git ls-files failed in (.+?) with status (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_context/src/bm25_context.rs","lineNumber":379,"sourceCode":"}\n\nasync fn git_ls_files(worktree_abs_path: &Path) -> Result<Vec<PathBuf>> {\n    let output = new_command(\"git\")\n        .arg(\"ls-files\")\n        .arg(\"-z\")\n        .current_dir(worktree_abs_path)\n        .output()\n        .await\n        .with_context(|| {\n            format!(\n                \"failed to run git ls-files in {}\",\n                worktree_abs_path.display()\n            )\n        })?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        bail!(\n            \"git ls-files failed in {} with status {}: {}\",\n            worktree_abs_path.display(),\n            output.status,\n            stderr.trim()\n        );\n    }\n\n    let output =\n        String::from_utf8(output.stdout).context(\"git ls-files output was not valid UTF-8\")?;\n    Ok(output\n        .split('\\0')\n        .filter(|path| !path.is_empty())\n        .map(PathBuf::from)\n        .collect())\n}\n\nfn documents_for_file(\n    worktree_abs_path: &Path,","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_context/src/bm25_context.rs#L361-L397","documentation":"Bailed when `git ls-files` executed inside a worktree exits with a non-zero status; the exit status and trimmed stderr are included in the message. The BM25 context builder runs this to enumerate tracked files, so any git-level failure — not a repository, dubious ownership, corrupted index — surfaces here before any context can be built.","triggerScenarios":"worktree_abs_path is not a git worktree; git refuses the repo with 'detected dubious ownership' (safe.directory); a corrupted .git/index; git not resolvable from the process environment.","commonSituations":"Pointing the context helper at a plain extracted directory (no .git); CI containers where the repo is owned by a different UID; spawned processes with a restricted PATH that can't find git.","solutions":["Run `git -C <worktree> ls-files` manually to see the underlying git error","For dubious ownership: `git config --global --add safe.directory <worktree-path>`","Confirm the path is a worktree: `git -C <worktree> rev-parse --is-inside-work-tree`","Ensure git is installed and reachable from the environment the helper inherits"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let ok = std::process::Command::new(\"git\")\n    .args([\"-C\", worktree.to_str().unwrap(), \"rev-parse\", \"--is-inside-work-tree\"])\n    .output()\n    .map(|o| o.status.success())\n    .unwrap_or(false);\nif !ok { /* skip BM25 context for this worktree instead of failing */ }","typeGuard":null,"tryCatchPattern":"Catch the bail, log the embedded git stderr, and degrade to serving the request without BM25 file-list context rather than failing the whole context lookup.","preventionTips":["Verify the worktree is a git repo before requesting BM25 context","Configure safe.directory for repos owned by other users (CI containers)","Ensure git is on PATH in the environment that spawns the helper"],"tags":["git","subprocess","context-retrieval","rust"],"backgroundTag":"git-subprocess-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}