{"record":{"id":"0344dc7e843de3db","repo":"nikivdev/code","slug":"git-failed-in","errorCode":null,"errorMessage":"git {} failed in {}","messagePattern":"git (.+?) failed in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pr_preview.rs","lineNumber":1542,"sourceCode":"\nfn git_rev_parse(repo_root: &Path, rev: &str) -> Result<String> {\n    git_capture_in(repo_root, &[\"rev-parse\", \"--verify\", \"--quiet\", rev])\n}\n\nfn git_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {\n    let output = Command::new(\"git\")\n        .current_dir(repo_root)\n        .args(args)\n        .output()\n        .with_context(|| {\n            format!(\n                \"failed to run git {} in {}\",\n                args.join(\" \"),\n                repo_root.display()\n            )\n        })?;\n    if !output.status.success() {\n        bail!(\"git {} failed in {}\", args.join(\" \"), repo_root.display());\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\nfn git_capture_for_preview(\n    repo_root: &Path,\n    work_tree_root: Option<&Path>,\n    args: &[&str],\n) -> Result<String> {\n    let mut command = Command::new(\"git\");\n    if let Some(work_tree_root) = work_tree_root {\n        command\n            .arg(\"--git-dir\")\n            .arg(repo_root.join(\".git\"))\n            .arg(\"--work-tree\")\n            .arg(work_tree_root)\n            .current_dir(work_tree_root);\n    } else {","sourceCodeStart":1524,"sourceCodeEnd":1560,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/pr_preview.rs#L1524-L1560","documentation":"Raised by the shared git command helper when a `git <subcommand>` invocation exits with a non-zero status in the given repo root. The message includes the exact git args and repo path so the failing operation can be reproduced. It indicates git ran but rejected the operation (bad ref, not a repo, dirty index, etc.).","triggerScenarios":"Any git command routed through this helper (e.g. `git rev-parse`, `git diff`, `git log`) failing: repo_root is not a git repository, a requested branch/commit SHA does not exist, or git's stderr reports a merge conflict or lock error.","commonSituations":"Running the preview in a directory without .git, referencing a branch that was deleted or renamed, a detached HEAD with no upstream, or a .git/index.lock left by a crashed git process.","solutions":["Re-run the exact `git <args>` shown in the message inside the reported repo root to see git's own error.","Verify the directory is a git repo: `git -C <repo_root> rev-parse --is-inside-work-tree`.","Check that the referenced branch/ref/commit exists (`git branch -a`, `git rev-parse <ref>`).","Remove a stale lock if present: delete .git/index.lock only when no git process is running."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify repo before calling\nif !repo_root.join(\".git\").exists() {\n    return Err(anyhow!(\"{} is not a git repository\", repo_root.display()));\n}","typeGuard":null,"tryCatchPattern":"match run_git(repo_root, &[\"rev-parse\", \"HEAD\"]) {\n    Ok(sha) => sha,\n    Err(e) => {\n        eprintln!(\"git unavailable in {}: {e}\", repo_root.display());\n        return Err(e);\n    }\n}","preventionTips":["Confirm the target directory is a git repo before running preview.","Validate referenced branches/refs exist before passing them to git.","Capture and log git stderr to make failures diagnosable.","Watch for stale .git/index.lock files in CI."],"tags":["git","subprocess","version-control"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}