{"record":{"id":"bc3ca3c1c9ce646a","repo":"affaan-m/ECC","slug":"git-diff-failed-stderr","errorCode":null,"errorMessage":"git diff failed: {stderr}","messagePattern":"git diff failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":1079,"sourceCode":"    let mut command = Command::new(\"git\");\n    command\n        .arg(\"-C\")\n        .arg(worktree_path)\n        .arg(\"diff\")\n        .args([\"--patch\", \"--find-renames\"]);\n    command.args(extra_args);\n    command.arg(\"--\");\n    for path in paths {\n        command.arg(path);\n    }\n\n    let output = command\n        .output()\n        .context(\"Failed to generate filtered git patch\")?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git diff failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).into_owned())\n}\n\nfn git_diff_patch_lines_for_paths(\n    worktree_path: &Path,\n    extra_args: &[&str],\n    paths: &[String],\n) -> Result<Vec<String>> {\n    if paths.is_empty() {\n        return Ok(Vec::new());\n    }\n\n    let mut command = Command::new(\"git\");\n    command\n        .arg(\"-C\")\n        .arg(worktree_path)","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L1061-L1097","documentation":"`git_diff_patch_text_for_paths` runs a filtered `git diff` and bails when the command exits non-zero, forwarding git's stderr. This is a wrapper over git plumbing, so the error means git itself rejected the diff invocation (bad rev, bad pathspec, corrupt index) — the message mirrors whatever git printed.","triggerScenarios":"Calling git_status_patch_view (which calls this function) when the repo has no HEAD yet (unborn branch), a pathspec matches nothing with certain flags, the index is corrupt/locked, or invalid refs are passed as path filters.","commonSituations":"Freshly `git init`ed repo with no commits; a race where the worktree's branch was deleted; an index.lock left by a crashed process; quoting issues in path arguments.","solutions":["Read the stderr in the message for git's specific complaint (e.g. 'fatal: ambiguous argument')","For unborn-branch repos, guard the call: only diff once HEAD exists ('git rev-parse HEAD' succeeds)","Remove a stale lock: check for .git/index.lock and delete it if no git process is running","Verify the paths passed as filters exist and are tracked, or pass '--' before pathspecs","Run 'git diff <same-args>' manually in the worktree to reproduce"],"exampleFix":"// before: fails on unborn HEAD\ngit_status_patch_view(&wt)?;\n// after: skip diff when HEAD missing\nlet has_head = Command::new(\"git\")\n    .args([\"rev-parse\", \"--verify\", \"HEAD\"])\n    .current_dir(&wt.path)\n    .output()?;\nlet view = if has_head.status.success() {\n    git_status_patch_view(&wt)?\n} else {\n    PatchView::default()\n};","handlingStrategy":"try-catch","validationCode":"let has_head = Command::new(\"git\")\n    .args([\"rev-parse\", \"--verify\", \"HEAD\"])\n    .current_dir(&wt.path)\n    .output()\n    .map(|o| o.status.success())\n    .unwrap_or(false);","typeGuard":null,"tryCatchPattern":"match git_status_patch_view(&wt) {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"ambiguous argument\") => {\n        // unborn HEAD (no commits yet) — treat as empty view\n        PatchView::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Only diff after the repo has at least one commit","Pass '--' before pathspecs to disambiguate paths from refs","Clear stale .git/index.lock files after crashed processes","Reproduce failing git diff args manually before filing issues"],"tags":["git","diff","command"],"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"}