{"record":{"id":"640e91e6c6413d68","repo":"affaan-m/ECC","slug":"git-log-failed-stderr","errorCode":null,"errorMessage":"git log failed: {stderr}","messagePattern":"git log failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":500,"sourceCode":"        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    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\npub fn create_draft_pr(worktree: &WorktreeInfo, title: &str, body: &str) -> Result<String> {\n    create_draft_pr_with_options(worktree, title, body, &DraftPrOptions::default())\n}\n\npub fn create_draft_pr_with_options(\n    worktree: &WorktreeInfo,\n    title: &str,\n    body: &str,\n    options: &DraftPrOptions,\n) -> Result<String> {\n    create_draft_pr_with_gh(worktree, title, body, options, Path::new(\"gh\"))\n}\n","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/worktree/mod.rs#L482-L518","documentation":"latest_commit_subject runs `git log -1 --pretty=%s`. Non-zero exit is re-thrown. The function is used to display the most recent commit; failure means HEAD has no commit to describe.","triggerScenarios":"Calling latest_commit_subject on a brand-new worktree whose branch has no commits yet (unborn HEAD); corrupted HEAD ref; the branch was reset to a state with zero commits.","commonSituations":"UI renders a 'last commit' field on a freshly created worktree before any commit; rebase left HEAD pointing at nothing during an interrupted operation; reflog corruption.","solutions":["Pre-check `git rev-parse --verify HEAD^{commit}` and only call latest_commit_subject when it resolves.","Render an 'empty branch' placeholder when there is no HEAD commit.","Run `git fsck` if HEAD should resolve but does not."],"exampleFix":"// before\nlet subject = latest_commit_subject(&worktree)?;\n\n// after\nlet has_head = Command::new(\"git\")\n    .arg(\"-C\").arg(&worktree.path)\n    .args([\"rev-parse\", \"--verify\", \"HEAD^{commit}\"])\n    .output()?.status.success();\nlet subject = if has_head {\n    Some(latest_commit_subject(&worktree)?)\n} else { None };","handlingStrategy":"validation","validationCode":"fn head_has_commit(worktree: &WorktreeInfo) -> bool {\n    std::process::Command::new(\"git\")\n        .arg(\"-C\").arg(&worktree.path)\n        .args([\"rev-parse\", \"--verify\", \"HEAD^{commit}\"])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}\n\nlet subject = if head_has_commit(&worktree) {\n    Some(latest_commit_subject(&worktree)?)\n} else {\n    None\n};","typeGuard":"fn has_commits(worktree: &WorktreeInfo) -> bool {\n    head_has_commit(worktree)\n}","tryCatchPattern":"match latest_commit_subject(&worktree) {\n    Ok(s) => Some(s),\n    Err(e) if format!(\"{e:#}\").contains(\"does not have any commits\") => None,\n    Err(e) if format!(\"{e:#}\").contains(\"unknown revision\") => None,\n    Err(e) => return Err(e),\n}","preventionTips":["Check `git rev-parse --verify HEAD^{commit}` before reading commit metadata.","Render an 'empty branch' state in the UI rather than calling latest_commit_subject blindly.","Run `git fsck` if HEAD should resolve but does not."],"tags":["git","subprocess","worktree","log","unborn-branch"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}