nikivdev/code · error
git log failed
Error message
git log failed
What it means
Thrown in `list_commits` (called by `run_list`) when the spawned `git log` process exits non-zero. Unlike the spawn failure (which yields 'failed to run git log'), this means git ran but rejected the arguments or repository state. Stderr from git is not embedded, so the message is generic.
Source
Thrown at src/commits.rs:167
limit: usize,
all_branches: bool,
top_hashes: &HashSet<String>,
) -> Result<Vec<CommitEntry>> {
let mut args = vec!["log", "--pretty=format:%h|%H|%s|%ar|%an", "-n"];
let limit_str = limit.to_string();
args.push(&limit_str);
if all_branches {
args.push("--all");
}
let output = Command::new("git")
.args(&args)
.output()
.context("failed to run git log")?;
if !output.status.success() {
bail!("git log failed");
}
let stdout = String::from_utf8_lossy(&output.stdout);
let mut commits = Vec::new();
for line in stdout.lines() {
let parts: Vec<&str> = line.splitn(5, '|').collect();
if parts.len() < 5 {
continue;
}
let hash = parts[0].to_string();
let full_hash = parts[1].to_string();
let subject = parts[2].to_string();
let relative_time = parts[3].to_string();
let author = parts[4].to_string();
// Check if commit has AI metadata (check git notes or commit trailers)View on GitHub (pinned to a747e741ae)
Solutions
- Run `git log` with the same args manually to see git's stderr explaining the failure
- If the repo is empty, make an initial commit before listing
- Validate any user-supplied revision/branch arguments before passing to list
- Confirm the working directory is inside a git repository
Defensive patterns
Strategy: validation
Validate before calling
// ensure we're in a repo with at least one commit before listing
let in_repo = Command::new("git").args(["rev-parse","--is-inside-work-tree"]).output()?.status.success();
let has_head = Command::new("git").args(["rev-parse","--verify","HEAD"]).output()?.status.success();
if !in_repo || !has_head {
eprintln!("no git history to list (empty repo or not a repository)");
return Ok(());
} Try / catch
match list_commits(&args) {
Err(e) if e.to_string() == "git log failed" => {
eprintln!("git log rejected the request — run git log manually with the same args to see why");
}
other => other?,
} Prevention
- Validate user-supplied revisions against `git rev-parse --verify` first
- Handle the empty-repository case (no HEAD) explicitly
- Run the tool only from inside a git work tree
- Capture git stderr and include it in the error for diagnosability
When it happens
Trigger: `git log` invoked with args that git rejects: invalid revision range, empty repository (no HEAD yet), bad --format/--max-count values, or running outside a git repository.
Common situations: Fresh `git init` repo with zero commits, typo'd branch/revision passed via CLI flags, repo with corrupted refs, or running the tool outside any git work tree.
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
- git add -- <paths> failed with status {}
- jj git export retry loop should always return
- Lin.app is not running
- external codex browser exited unsuccessfully with status {}
- No branches available to search
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/27f707a7c21c0642.
Report an issue: GitHub.