{"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":null,"httpStatus":null,"severity":"error","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/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L465-L501","documentation":"After a successful commit, commit_staged resolves the new HEAD with `git rev-parse --short HEAD` to return the short hash. If that command exits non-zero the library throws this error; the commit likely succeeded but the hash could not be resolved, which points to a repository-state problem.","triggerScenarios":"Calling commit_staged when the follow-up rev-parse fails: another process detached HEAD or ran `git update-ref -d HEAD` between commit and rev-parse, repository corruption, or the commit actually failed silently in an edge case leaving HEAD unborn.","commonSituations":"Concurrent tooling mutating the repo mid-operation; corrupted .git/refs; running in an environment where git is a different version/shim misbehaving; very rare race with a parallel commit/checkout.","solutions":["Re-run git status / rev-parse manually to inspect repository state; the commit may still exist (check `git log -1`).","Retry commit_staged if the race was transient and no commit was created — but first verify with `git log` to avoid duplicate commits.","Investigate repository integrity with `git fsck` if errors persist.","Avoid running concurrent git-mutating operations (IDE + this library) on the same worktree."],"exampleFix":"// caller-side: handle partial success\nmatch commit_staged(&worktree, msg) {\n    Ok(hash) => println!(\"committed {hash}\"),\n    Err(e) if e.to_string().contains(\"rev-parse\") => {\n        // commit may exist; check before retrying\n        let head = current_head(&worktree)?;\n        println!(\"recoverable, HEAD={head}\");\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"retry","validationCode":"fn head_resolvable(worktree: &WorktreeInfo) -> bool {\n    Command::new(\"git\").arg(\"-C\").arg(&worktree.path)\n        .args([\"rev-parse\", \"--verify\", \"HEAD\"])\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":"None","tryCatchPattern":"match commit_staged(&worktree, &msg) {\n    Ok(hash) => Ok(hash),\n    Err(e) if e.to_string().contains(\"rev-parse\") => {\n        // commit likely succeeded; resolve HEAD once before retrying\n        std::thread::sleep(std::time::Duration::from_millis(50));\n        resolve_head(&worktree)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Treat a rev-parse failure after commit as a possible partial success — check `git log -1` before re-committing.","Avoid running concurrent git-mutating operations on the same worktree.","Run `git fsck` if rev-parse failures recur, to rule out repository corruption."],"tags":["git","rev-parse","command-failed","race-condition"],"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"}