nikivdev/code · error
git status failed with {}
Error message
git status failed with {} What it means
The library runs `git status --porcelain --untracked-files=all` in the project root to enumerate changed paths; when git exits non-zero it wraps the exit status into this error. It almost always reflects a broken git environment rather than a library bug.
Source
Thrown at src/codex_session_docs.rs:1451
|| entry.session_key.starts_with(session_hint))
})
.map(|(index, _)| index)
.collect::<Vec<_>>();
match matches.as_slice() {
[index] => Ok(*index),
[] => bail!("no session-doc queue entry matches `{session_hint}`"),
_ => bail!("multiple session-doc queue entries match `{session_hint}`"),
}
}
fn git_changed_paths(project_root: &Path) -> Result<Vec<String>> {
let output = Command::new("git")
.args(["status", "--porcelain", "--untracked-files=all"])
.current_dir(project_root)
.output()
.context("failed to run git status")?;
if !output.status.success() {
bail!("git status failed with {}", output.status);
}
let stdout = String::from_utf8_lossy(&output.stdout);
let mut paths = Vec::new();
for line in stdout.lines() {
if line.len() < 4 {
continue;
}
let raw_path = line[3..].trim();
let path = raw_path
.split_once(" -> ")
.map(|(_, after)| after)
.unwrap_or(raw_path);
if !path.is_empty() {
paths.push(path.to_string());
}
}
Ok(dedupe_preserve_order(paths))
}View on GitHub (pinned to a747e741ae)
Solutions
- Run `git status` manually in the project root to see the real git error
- Initialize the repo (`git init`) if the directory is not one, or point the tool at the repo root
- Fix git config issues (e.g. `git config --global --add safe.directory <path>`) and remove stale `index.lock`
Example fix
// before
let paths = git_changed_paths(root)?;
// after
ensure!(root.join(".git").exists(), "{} is not a git repo", root.display());
let paths = git_changed_paths(root)?; Defensive patterns
Strategy: validation
Validate before calling
let probe = Command::new("git").args(["rev-parse","--is-inside-work-tree"]).current_dir(root).output()?;
anyhow::ensure!(probe.status.success(),
"git unusable in {}: {}", root.display(), String::from_utf8_lossy(&probe.stderr)); Type guard
fn is_usable_git_repo(root: &Path) -> bool {
Command::new("git").args(["rev-parse","--is-inside-work-tree"])
.current_dir(root).output().map(|o| o.status.success()).unwrap_or(false)
} Try / catch
match git_changed_paths(root) {
Err(e) if e.to_string().contains("git status failed") => {
eprintln!("{} — run `git status` manually in {} to see the cause", e, root.display());
Err(e)
}
other => other,
} Prevention
- Verify the working directory is a healthy git repo before invoking the tool
- Add `safe.directory` config when repos are shared across users/containers
- Check for `.git/index.lock` and disk/permission issues in CI images
When it happens
Trigger: `git status` returning a non-zero exit status inside the project root — e.g. the directory is not a git repository, `.git` is corrupted, or git cannot read the index/ownership config.
Common situations: Running the tool outside a repo; "dubious ownership" after copying repos across users/containers; permission problems on `.git/index.lock`; broken git installation.
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
- Lin.app is not running
- failed to stash working tree: {}
- git add failed with {}
- git commit failed with {}
- failed to resolve git repo root
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/e0eee2755a4ee623.
Report an issue: GitHub.