{"record":{"id":"27f707a7c21c0642","repo":"nikivdev/code","slug":"git-log-failed","errorCode":null,"errorMessage":"git log failed","messagePattern":"git log failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commits.rs","lineNumber":167,"sourceCode":"    limit: usize,\n    all_branches: bool,\n    top_hashes: &HashSet<String>,\n) -> Result<Vec<CommitEntry>> {\n    let mut args = vec![\"log\", \"--pretty=format:%h|%H|%s|%ar|%an\", \"-n\"];\n    let limit_str = limit.to_string();\n    args.push(&limit_str);\n\n    if all_branches {\n        args.push(\"--all\");\n    }\n\n    let output = Command::new(\"git\")\n        .args(&args)\n        .output()\n        .context(\"failed to run git log\")?;\n\n    if !output.status.success() {\n        bail!(\"git log failed\");\n    }\n\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    let mut commits = Vec::new();\n\n    for line in stdout.lines() {\n        let parts: Vec<&str> = line.splitn(5, '|').collect();\n        if parts.len() < 5 {\n            continue;\n        }\n\n        let hash = parts[0].to_string();\n        let full_hash = parts[1].to_string();\n        let subject = parts[2].to_string();\n        let relative_time = parts[3].to_string();\n        let author = parts[4].to_string();\n\n        // Check if commit has AI metadata (check git notes or commit trailers)","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commits.rs#L149-L185","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure we're in a repo with at least one commit before listing\nlet in_repo = Command::new(\"git\").args([\"rev-parse\",\"--is-inside-work-tree\"]).output()?.status.success();\nlet has_head = Command::new(\"git\").args([\"rev-parse\",\"--verify\",\"HEAD\"]).output()?.status.success();\nif !in_repo || !has_head {\n    eprintln!(\"no git history to list (empty repo or not a repository)\");\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"match list_commits(&args) {\n    Err(e) if e.to_string() == \"git log failed\" => {\n        eprintln!(\"git log rejected the request — run git log manually with the same args to see why\");\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["git","external-process","logging"],"backgroundTag":"git-command-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}