affaan-m/ECC · error

git log failed

Error message

git log failed: {stderr}

What it means

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.

Solutions

  1. Check the stderr in the message — it names the actual git failure (e.g. 'does not have any commits yet').
  2. Create an initial commit in the worktree: `git commit --allow-empty -m "init"` if HEAD is unborn.
  3. Verify the path is a valid git worktree: `git -C <path> rev-parse --git-dir`.
  4. Re-create the worktree with `git worktree add` if its metadata is missing or corrupt.
  5. Confirm no GIT_* environment variables override the repository location in your shell/CI.
Defensive patterns

Strategy: validation

Validate before calling

fn worktree_has_commits(path: &Path) -> bool {
    Command::new("git").arg(path).args(["rev-parse", "--verify", "HEAD"])
        .output().map(|o| o.status.success()).unwrap_or(false)
}

Type guard

fn is_git_repo(path: &Path) -> bool {
    Command::new("git").arg(path).args(["rev-parse", "--git-dir"])
        .output().map(|o| o.status.success()).unwrap_or(false)
}

Try / catch

match latest_commit_subject(&wt) {
    Ok(subject) => use(subject),
    Err(e) => log::warn!("no commit subject for {}: {e:#}", wt.branch),
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/640e91e6c6413d68. Report an issue: GitHub.

Appendix: source

Thrown at ecc2/src/worktree/mod.rs:500

        let stderr = String::from_utf8_lossy(&rev_parse.stderr);
        anyhow::bail!("git rev-parse failed: {stderr}");
    }

    Ok(String::from_utf8_lossy(&rev_parse.stdout)
        .trim()
        .to_string())
}

pub fn latest_commit_subject(worktree: &WorktreeInfo) -> Result<String> {
    let output = Command::new("git")
        .arg("-C")
        .arg(&worktree.path)
        .args(["log", "-1", "--pretty=%s"])
        .output()
        .context("Failed to read latest commit subject")?;
    if !output.status.success() {
        let stderr = String::from_utf8_lossy(&output.stderr);
        anyhow::bail!("git log failed: {stderr}");
    }

    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}

pub fn create_draft_pr(worktree: &WorktreeInfo, title: &str, body: &str) -> Result<String> {
    create_draft_pr_with_options(worktree, title, body, &DraftPrOptions::default())
}

pub fn create_draft_pr_with_options(
    worktree: &WorktreeInfo,
    title: &str,
    body: &str,
    options: &DraftPrOptions,
) -> Result<String> {
    create_draft_pr_with_gh(worktree, title, body, options, Path::new("gh"))
}

View on GitHub (pinned to 8321021c54)