{"record":{"id":"ea059c800e07e0bb","repo":"zed-industries/zed","slug":"git-log-failed-in-with-status","errorCode":null,"errorMessage":"git log failed in {} with status {}: {}","messagePattern":"git log failed in (.+?) with status (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/edit_prediction_context/src/git_log_context.rs","lineNumber":94,"sourceCode":"    }\n}\n\npub async fn build_git_log_index(worktree_dir: &Path) -> Result<GitLogIndex> {\n    let mut index = GitLogIndex::new();\n\n    let output = new_command(\"git\")\n        .arg(\"log\")\n        .arg(\"-5000\")\n        .arg(\"--pretty=tformat:@@COMMIT %H\")\n        .arg(\"--name-only\")\n        .current_dir(worktree_dir)\n        .output()\n        .await\n        .with_context(|| format!(\"failed to run git log in {}\", worktree_dir.display()))?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        bail!(\n            \"git log failed in {} with status {}: {}\",\n            worktree_dir.display(),\n            output.status,\n            stderr.trim()\n        );\n    }\n\n    let log = String::from_utf8(output.stdout).context(\"git log output was not valid UTF-8\")?;\n    let parsed = parse_git_log(&log);\n    for files in parsed {\n        for i in 0..files.len() {\n            for j in (i + 1)..files.len() {\n                index.add_related(files[i].clone(), files[j].clone());\n            }\n        }\n    }\n\n    Ok(index)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/edit_prediction_context/src/git_log_context.rs#L76-L112","documentation":"Bailed when `git log -5000 --pretty=... --name-only` executed in the worktree directory exits non-zero; the status and stderr are embedded. The git-log context builder mines co-occurrence of file paths across the last 5000 commits, so this fails before the related-files index can be built.","triggerScenarios":"worktree_dir is not a git repository; 'detected dubious ownership' rejection; broken object database after an interrupted operation; git missing from the helper's PATH when spawned from the editor.","commonSituations":"Running the context provider on non-git folders; containerized/CI environments with mismatched repo ownership; shallow clones with damaged refs.","solutions":["Run `git -C <dir> log -5000 --name-only` by hand to reproduce the git failure","Add the path to safe.directory if git reports dubious ownership","Verify the directory is a git repo (`git -C <dir> rev-parse --is-inside-work-tree`) before requesting git-log context","Confirm git is on PATH for the process launching the helper binary"],"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 git-log context for this worktree instead of failing */ }","typeGuard":null,"tryCatchPattern":"Catch the bail, log the git status/stderr from the message, and fall back to running without the git-log related-files index.","preventionTips":["Pre-check that the worktree resolves as a git repo","Add CI-owned repo paths to safe.directory","Pin the git binary via env when spawning helpers from editors with minimal PATH"],"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-14T05:17:10.506Z"}