{"record":{"id":"4110b9aba1dee815","repo":"affaan-m/ECC","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":"ecc2/src/worktree/mod.rs","lineNumber":283,"sourceCode":"\n    if parts.is_empty() {\n        Ok(Some(format!(\"Clean relative to {}\", worktree.base_branch)))\n    } else {\n        Ok(Some(parts.join(\" | \")))\n    }\n}\n\npub fn git_status_entries(worktree: &WorktreeInfo) -> Result<Vec<GitStatusEntry>> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"status\", \"--porcelain=v1\", \"--untracked-files=all\"])\n        .output()\n        .context(\"Failed to load git status entries\")?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git status failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout)\n        .lines()\n        .filter_map(parse_git_status_entry)\n        .collect())\n}\n\npub fn stage_path(worktree: &WorktreeInfo, path: &str) -> Result<()> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"add\", \"--\"])\n        .arg(path)\n        .output()\n        .with_context(|| format!(\"Failed to stage {}\", path))?;\n    if output.status.success() {\n        Ok(())","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L265-L301","documentation":"git_status_entries runs `git status --porcelain=v1 --untracked-files=all` in the worktree. A non-zero exit status triggers this error carrying git's stderr. It is a thin wrapper around git, so any reason git status fails is surfaced verbatim.","triggerScenarios":"Calling has_staged_changes / git_status_entries on a WorktreeInfo whose path no longer exists (worktree pruned), points outside a git repository, or where the underlying git index is corrupt/locked.","commonSituations":"Worktree removed externally with `git worktree prune` while the session still holds its path; running in a bare repo without a worktree; a stale `.git/index.lock` left by a crashed git process; symlinked worktree path broken after a move.","solutions":["Verify the worktree path exists and is a valid git worktree (`git -C <path> rev-parse --is-inside-work-tree`) before calling","Recreate the worktree via create_for_session if it was pruned","Delete a stale `<worktree>/.git/index.lock` if git reports index lock errors","Check the stderr text in the error — 'not a git repository' vs 'index.lock' vs 'bad object' indicate different fixes"],"exampleFix":"// before\nif has_staged_changes(&worktree)? { ... }\n// after\nif Path::new(&worktree.path).exists() && git_worktree_valid(&worktree.path)? {\n    if has_staged_changes(&worktree)? { ... }\n}","handlingStrategy":"try-catch","validationCode":"// Confirm the worktree is usable before git operations\nfn worktree_usable(path: &Path) -> bool {\n    path.exists()\n        && Command::new(\"git\").arg(\"-C\").arg(path)\n            .args([\"rev-parse\", \"--is-inside-work-tree\"])\n            .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match git_status_entries(&worktree) {\n    Ok(entries) => entries,\n    Err(e) if e.to_string().contains(\"index.lock\") => {\n        std::fs::remove_file(worktree.path.join(\".git/index.lock\")).ok();\n        git_status_entries(&worktree)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Verify the worktree path still exists before each git operation (it may have been pruned externally)","Remove stale .git/index.lock files left by crashed git processes","Run git operations in the worktree serially or with a per-worktree lock to avoid races"],"tags":["git","worktree","rust","process"],"backgroundTag":"git-command-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}