{"record":{"id":"b22ef6d221b5da20","repo":"affaan-m/ECC","slug":"git-rev-parse-failed-stderr","errorCode":null,"errorMessage":"git rev-parse failed: {stderr}","messagePattern":"git rev-parse failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"ecc2/src/worktree/mod.rs","lineNumber":483,"sourceCode":"        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"commit\", \"-m\", message])\n        .output()\n        .context(\"Failed to create commit\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git commit failed: {stderr}\");\n    }\n\n    let rev_parse = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"rev-parse\", \"--short\", \"HEAD\"])\n        .output()\n        .context(\"Failed to resolve commit hash\")?;\n    if !rev_parse.status.success() {\n        let stderr = String::from_utf8_lossy(&rev_parse.stderr);\n        anyhow::bail!(\"git rev-parse failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&rev_parse.stdout)\n        .trim()\n        .to_string())\n}\n\npub fn latest_commit_subject(worktree: &WorktreeInfo) -> Result<String> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&worktree.path)\n        .args([\"log\", \"-1\", \"--pretty=%s\"])\n        .output()\n        .context(\"Failed to read latest commit subject\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git log failed: {stderr}\");\n    }","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/worktree/mod.rs#L465-L501","documentation":"Right after a successful `git commit`, commit_staged runs `git rev-parse --short HEAD` to capture the new commit's short hash. A non-zero exit at this point is highly unusual: the commit just succeeded, so HEAD should resolve. Failure usually indicates repository corruption or that the commit step did not actually advance HEAD despite exiting zero.","triggerScenarios":"The commit's pre-commit hook performed a reset/amend that left HEAD detached or unborn; the object database was corrupted by disk pressure between commit and rev-parse; a concurrent process moved HEAD to a state where `--short` formatting fails (rare).","commonSituations":"Disk-full during commit object write; aggressive background GC packed the new object away inconsistently; sandboxed filesystem that loses the new loose object.","solutions":["Run `git -C <path> fsck --no-dangling` to detect corruption.","Check disk space on the volume holding the repo.","Re-read HEAD with `git -C <path> log -1 --pretty=%H` to confirm the commit landed; if not, retry the commit.","Surface the rev-parse stderr verbatim — it usually points at the corruption type."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// There is no caller-side validation that prevents repository corruption.\n// Best pre-check: confirm the commit actually landed before trusting it.\nfn head_short(worktree: &WorktreeInfo) -> anyhow::Result<String> {\n    let out = std::process::Command::new(\"git\")\n        .arg(\"-C\").arg(&worktree.path)\n        .args([\"log\", \"-1\", \"--pretty=%h\"])\n        .output()?;\n    if !out.status.success() {\n        anyhow::bail!(\"HEAD did not resolve after commit\");\n    }\n    Ok(String::from_utf8_lossy(&out.stdout).trim().to_string())\n}","typeGuard":null,"tryCatchPattern":"match commit_staged(&worktree, msg) {\n    Ok(hash) => Ok(hash),\n    Err(e) if format!(\"{e:#}\").contains(\"rev-parse failed\") => {\n        // fall back to `git log -1 --pretty=%h`; if that also fails, run fsck\n        Err(e).with_context(|| \"post-commit rev-parse failed; run `git fsck`\")\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Monitor disk space on the repo volume; loose-object writes fail silently under disk pressure.","Run `git fsck` periodically on long-lived worktrees to catch object corruption early.","Disable concurrent `git gc`/commit on the same repo to avoid object DB races.","After this error, verify the commit landed (`git log -1`) before assuming success."],"tags":["git","subprocess","worktree","commit","corruption"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}