{"record":{"id":"1e92d94fc154cef3","repo":"Hmbown/CodeWhale","slug":"git-diff-failed","errorCode":null,"errorMessage":"git diff failed: {}","messagePattern":"git diff failed: (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9858,"sourceCode":"        // Review repository content without executing its diff drivers.\n        cmd.current_dir(workspace)\n            .args([\"diff\", \"--no-ext-diff\", \"--no-textconv\"]);\n        if args.staged {\n            cmd.arg(\"--cached\");\n        }\n        if let Some(base) = &args.base {\n            cmd.arg(format!(\"{base}...HEAD\"));\n        }\n        if let Some(path) = &args.path {\n            cmd.arg(\"--\").arg(path);\n        }\n\n        let output = cmd\n            .output()\n            .map_err(|e| anyhow::anyhow!(\"Failed to run git diff. Is git installed? ({e})\"))?;\n        if !output.status.success() {\n            let stderr = String::from_utf8_lossy(&output.stderr);\n            bail!(\"git diff failed: {}\", stderr.trim());\n        }\n        String::from_utf8_lossy(&output.stdout).to_string()\n    };\n    if args.pr.is_none() {\n        ensure_local_review_diff_fits(&diff, args.max_chars)?;\n    }\n    Ok(diff)\n}\n\nfn ensure_local_review_diff_fits(diff: &str, max_chars: usize) -> Result<()> {\n    let chars = diff.chars().count();\n    if chars > max_chars {\n        bail!(\n            \"Complete local diff requires {chars} characters, exceeding the review limit of {max_chars}. No review was run and no receipt was written or accepted. Select an explicit --path scope, or increase --max-chars only if the selected model can accept the complete input.\"\n        );\n    }\n    Ok(())\n}","sourceCodeStart":9840,"sourceCodeEnd":9876,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L9840-L9876","documentation":"The local code-review path runs `git diff` as a subprocess to collect the diff for review. If git exits non-zero, its trimmed stderr is wrapped in this error. It indicates the diff could not be produced in the current working tree.","triggerScenarios":"`git diff` exits non-zero: not inside a git repository, corrupted index/lock file, invalid path arguments passed via --path, or git object store issues.","commonSituations":"Running the review command outside a repo (or in a subdirectory of a non-repo); leftover `.git/index.lock` from a crashed git process; passing a --path that git's pathspec parser rejects.","solutions":["Run `git diff` manually in the target directory to see the underlying git error","Confirm the working directory is inside a git repository (`git rev-parse --is-inside-work-tree`)","Remove a stale `.git/index.lock` if present, then retry"],"exampleFix":"// before\n$ cd ~/not-a-repo && codewhale review --path .\nerror: git diff failed: fatal: not a git repository\n// after\n$ cd ~/my-repo && codewhale review --path .","handlingStrategy":"validation","validationCode":"if !std::path::Path::new(\".git\").exists() && std::process::Command::new(\"git\").args([\"rev-parse\",\"--is-inside-work-tree\"]).output().map(|o| !o.status.success()).unwrap_or(true) { /* not a repo — bail early */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run review commands from inside the repository root","Clear stale .git/index.lock after crashes","Validate --path arguments are real repo-relative pathspecs before invoking"],"tags":["cli","git","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}