nikivdev/code · error

git commit failed with {}

Error message

git commit failed with {}

What it means

The final `git commit -m <message>` for the documentation snapshot exited non-zero, so the library surfaces the exit status. This typically means git itself refused the commit (identity not configured, nothing staged, hooks failing, or lock contention).

Source

Thrown at src/codex_session_docs.rs:1521

        .arg("add")
        .arg("--")
        .args(paths)
        .status()
        .context("failed to run git add")?;
    if !status.success() {
        bail!("git add failed with {}", status);
    }
    Ok(())
}

fn git_commit_paths(project_root: &Path, message: &str) -> Result<()> {
    let status = Command::new("git")
        .current_dir(project_root)
        .args(["commit", "-m", message])
        .status()
        .context("failed to run git commit")?;
    if !status.success() {
        bail!("git commit failed with {}", status);
    }
    Ok(())
}

fn build_doc_commit_message(
    entries: &[DocReviewQueueEntry],
    candidate_indexes: &[usize],
) -> String {
    if candidate_indexes.len() == 1 {
        let entry = &entries[candidate_indexes[0]];
        let topic = entry
            .changed_files
            .first()
            .map(|path| slugify(path, 40))
            .filter(|value| !value.is_empty())
            .unwrap_or_else(|| entry.session_key.clone());
        return format!("docs(ai): capture codex session changes for {}", topic);
    }

View on GitHub (pinned to a747e741ae)

Solutions

  1. Set `git config user.name` and `git config user.email` in the repo or globally
  2. Run `git commit` manually after staging to see the actual git error
  3. Bypass/fix failing hooks (`--no-verify`) or the signing config if appropriate

Example fix

// before
let status = git_commit_paths(root, msg)?;
// after
if !repo_has_git_identity() {
    run_git(root, ["config", "user.email", "docs-bot@example.com"])?;
    run_git(root, ["config", "user.name", "Docs Bot"])?;
}
let status = git_commit_paths(root, msg)?;
Defensive patterns

Strategy: try-catch

Validate before calling

fn has_git_identity(root: &Path) -> bool {
    Command::new("git").args(["config","user.email"]).current_dir(root)
        .output().map(|o| o.status.success() && !o.stdout.is_empty()).unwrap_or(false)
}
anyhow::ensure!(has_git_identity(root), "configure git user.name/user.email before committing");

Type guard

fn can_commit(root: &Path) -> bool {
    has_git_identity(root) && is_usable_git_repo(root)
}

Try / catch

match git_commit_paths(root, msg) {
    Err(e) if e.to_string().contains("git commit failed") => {
        eprintln!("{} — check git identity, hooks, and signing config", e);
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: `git commit` failing in the project root during the doc commit step — missing user.name/user.email, commit hooks returning failure, nothing to commit, or GPG signing issues.

Common situations: Fresh CI machines without git identity configured; corporate hooks (lint/sign) rejecting auto-generated commit messages; GPG key passphrase prompts in non-interactive shells.

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 nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/fcf8fe016e4b1424. Report an issue: GitHub.