{"record":{"id":"e0eee2755a4ee623","repo":"nikivdev/code","slug":"git-status-failed-with","errorCode":null,"errorMessage":"git status failed with {}","messagePattern":"git status failed with (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/codex_session_docs.rs","lineNumber":1451,"sourceCode":"                    || entry.session_key.starts_with(session_hint))\n        })\n        .map(|(index, _)| index)\n        .collect::<Vec<_>>();\n    match matches.as_slice() {\n        [index] => Ok(*index),\n        [] => bail!(\"no session-doc queue entry matches `{session_hint}`\"),\n        _ => bail!(\"multiple session-doc queue entries match `{session_hint}`\"),\n    }\n}\n\nfn git_changed_paths(project_root: &Path) -> Result<Vec<String>> {\n    let output = Command::new(\"git\")\n        .args([\"status\", \"--porcelain\", \"--untracked-files=all\"])\n        .current_dir(project_root)\n        .output()\n        .context(\"failed to run git status\")?;\n    if !output.status.success() {\n        bail!(\"git status failed with {}\", output.status);\n    }\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    let mut paths = Vec::new();\n    for line in stdout.lines() {\n        if line.len() < 4 {\n            continue;\n        }\n        let raw_path = line[3..].trim();\n        let path = raw_path\n            .split_once(\" -> \")\n            .map(|(_, after)| after)\n            .unwrap_or(raw_path);\n        if !path.is_empty() {\n            paths.push(path.to_string());\n        }\n    }\n    Ok(dedupe_preserve_order(paths))\n}","sourceCodeStart":1433,"sourceCodeEnd":1469,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/codex_session_docs.rs#L1433-L1469","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Running the tool outside a repo; \"dubious ownership\" after copying repos across users/containers; permission problems on `.git/index.lock`; broken git installation.","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`"],"exampleFix":"// before\nlet paths = git_changed_paths(root)?;\n// after\nensure!(root.join(\".git\").exists(), \"{} is not a git repo\", root.display());\nlet paths = git_changed_paths(root)?;","handlingStrategy":"validation","validationCode":"let probe = Command::new(\"git\").args([\"rev-parse\",\"--is-inside-work-tree\"]).current_dir(root).output()?;\nanyhow::ensure!(probe.status.success(),\n    \"git unusable in {}: {}\", root.display(), String::from_utf8_lossy(&probe.stderr));","typeGuard":"fn is_usable_git_repo(root: &Path) -> bool {\n    Command::new(\"git\").args([\"rev-parse\",\"--is-inside-work-tree\"])\n        .current_dir(root).output().map(|o| o.status.success()).unwrap_or(false)\n}","tryCatchPattern":"match git_changed_paths(root) {\n    Err(e) if e.to_string().contains(\"git status failed\") => {\n        eprintln!(\"{} — run `git status` manually in {} to see the cause\", e, root.display());\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["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"],"tags":["git","subprocess","repository"],"backgroundTag":"git-command-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}