{"record":{"id":"a12fe5f9de88f2d8","repo":"zed-industries/zed","slug":"git-status-failed-stderr","errorCode":null,"errorMessage":"git status failed: {stderr}","messagePattern":"git status failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/git/src/repository.rs","lineNumber":1843,"sourceCode":"                    return Ok(Vec::new());\n                }\n                if let Some(revision) = revisions.iter().find(|revision| revision.contains('\\n')) {\n                    anyhow::bail!(\n                        \"revision spec {revision:?} contains a newline and cannot be passed to git cat-file --batch\"\n                    );\n                }\n\n                let mut process = git\n                    .build_command(&[\"cat-file\", \"--batch\"])\n                    .stdin(Stdio::piped())\n                    .stdout(Stdio::piped())\n                    .stderr(Stdio::piped())\n                    .kill_on_drop(true)\n                    .spawn()?;\n\n                let mut stdin = BufWriter::new(process.stdin.take().context(\"no stdin\")?);\n                let mut stdout = BufReader::new(process.stdout.take().context(\"no stdout\")?);\n                let mut newline = [0u8; 1];\n\n                let mut header_bytes = Vec::new();\n                let mut results = Vec::with_capacity(revisions.len());\n                for rev in &revisions {\n                    stdin.write_all(rev.as_bytes()).await?;\n                    stdin.write_all(b\"\\n\").await?;\n                    stdin.flush().await?;\n\n                    header_bytes.clear();\n                    stdout.read_until(b'\\n', &mut header_bytes).await?;\n                    let header_line = String::from_utf8_lossy(&header_bytes);\n\n                    let parts: Vec<&str> = header_line.trim().split(' ').collect();\n                    match parts[..] {\n                        [.., \"missing\"] => {\n                            results.push(None);\n                        }\n                        [_, object_type, size_str] => {","sourceCodeStart":1825,"sourceCodeEnd":1861,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/git/src/repository.rs#L1825-L1861","documentation":"Repository status() runs `git status --porcelain=v1 --untracked-files=all --no-renames -z` and, when the process exits non-zero, wraps git's stderr in this message. The wrapper is not the cause: the appended stderr text names the actual git failure (ownership, permissions, lock files, bare repo, and so on).","triggerScenarios":"Any condition that makes `git status` fail in the worktree: `fatal: this operation must be run in a work tree` for a bare repository, `error: Insufficient permissions`, a stale or unreadable `.git/index.lock`, `fatal: detected dubious ownership in repository`, or a missing/corrupt HEAD ref.","commonSituations":"Repositories owned by another user or root (dubious ownership on newer git), repos on network mounts with permission problems, a leftover index.lock after a crashed git process, pointing tooling at a bare repo instead of a worktree, or extremely old git versions lacking porcelain v1 flags.","solutions":["Read the appended stderr first and act on that specific git message.","For `detected dubious ownership`: `git config --global --add safe.directory /path/to/repo`.","For `index.lock`: confirm no git process is running, then remove the stale `.git/index.lock`.","For bare repos, target a worktree of the bare repository rather than the bare path itself.","Verify permissions on `.git` and that the installed git supports `--porcelain=v1 -z`."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// preflight before the first status call\ngit.run(&[\"rev-parse\", \"--is-inside-work-tree\"]).await?;","typeGuard":null,"tryCatchPattern":"if let Err(e) = repo.status(&prefixes).await {\n    let msg = e.to_string();\n    if msg.contains(\"dubious ownership\") {\n        // instruct user to run: git config --global --add safe.directory <path>\n    } else if msg.contains(\"index.lock\") {\n        // stale lock: suggest cleanup after confirming no git process runs\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Ensure the process runs as a user with read access to .git (avoid root-owned checkouts).","Configure safe.directory for repositories not owned by the running user.","Never kill git processes mid-status; a leftover index.lock breaks subsequent status calls.","Surface git's stderr verbatim to users — the wrapper message alone is not diagnosable."],"tags":["git","status","subprocess","stderr"],"backgroundTag":"git-command-failed","analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}