{"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":null,"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/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L482-L518","documentation":"latest_commit_subject runs `git log -1 --pretty=%s` inside the worktree to read the most recent commit's subject line. This error is raised when git itself exits nonzero, and the raw stderr is appended to the message. The library surfaces git's own diagnostic so the caller can see the underlying repository problem.","triggerScenarios":"Calling latest_commit_subject on a worktree path that is not a git repository, has no commits (unborn HEAD), a corrupt repository, or where the git binary cannot resolve refs (e.g. detached/broken HEAD or permission issues on .git).","commonSituations":"Pointing the tool at a directory initialized with `git init` but with zero commits; a worktree whose gitdir was pruned or deleted; running in an environment where GIT_DIR/GIT_WORK_TREE env vars point elsewhere; corrupted object database after a failed sync.","solutions":["Check the stderr in the message — it names the actual git failure (e.g. 'does not have any commits yet').","Create an initial commit in the worktree: `git commit --allow-empty -m \"init\"` if HEAD is unborn.","Verify the path is a valid git worktree: `git -C <path> rev-parse --git-dir`.","Re-create the worktree with `git worktree add` if its metadata is missing or corrupt.","Confirm no GIT_* environment variables override the repository location in your shell/CI."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn worktree_has_commits(path: &Path) -> bool {\n    Command::new(\"git\").arg(path).args([\"rev-parse\", \"--verify\", \"HEAD\"])\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":"fn is_git_repo(path: &Path) -> bool {\n    Command::new(\"git\").arg(path).args([\"rev-parse\", \"--git-dir\"])\n        .output().map(|o| o.status.success()).unwrap_or(false)\n}","tryCatchPattern":"match latest_commit_subject(&wt) {\n    Ok(subject) => use(subject),\n    Err(e) => log::warn!(\"no commit subject for {}: {e:#}\", wt.branch),\n}","preventionTips":["Ensure each worktree has at least one commit before querying","Validate the path with `git rev-parse --git-dir` at startup","Avoid GIT_* env overrides in the process environment","Recreate worktrees whose gitdir was pruned"],"tags":["git","worktree","process"],"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"}