{"record":{"id":"f3fe818e87a214da","repo":"denoland/deno","slug":"git-failed","errorCode":null,"errorMessage":"`git {}` failed: {}","messagePattern":"`git (.+?)` failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"cli/util/git.rs","lineNumber":26,"sourceCode":"use tokio::process::Command;\n\n/// Run `git` with `args` in `cwd`, returning stdout on success.\npub fn run_git(cwd: &Path, args: &[&str]) -> Result<String, AnyError> {\n  let output = match std::process::Command::new(\"git\")\n    .current_dir(cwd)\n    .args(args)\n    .output()\n  {\n    Ok(output) => output,\n    Err(err) => {\n      return Err(anyhow!(\n        \"Failed to run `git {}`: {err}. Is git installed and on PATH?\",\n        args.join(\" \")\n      ));\n    }\n  };\n  if !output.status.success() {\n    return Err(anyhow!(\n      \"`git {}` failed: {}\",\n      args.join(\" \"),\n      String::from_utf8_lossy(&output.stderr).trim()\n    ));\n  }\n  Ok(String::from_utf8_lossy(&output.stdout).into_owned())\n}\n\npub async fn check_if_git_repo_dirty(cwd: &Path) -> Option<String> {\n  let bin_name = if cfg!(windows) { \"git.exe\" } else { \"git\" };\n\n  //  Check if git exists\n  let git_exists = Command::new(bin_name)\n    .arg(\"--version\")\n    .stderr(Stdio::null())\n    .stdout(Stdio::null())\n    .status()\n    .await","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/util/git.rs#L8-L44","documentation":"run_git got git to start but it exited non-zero; the message embeds the exact git arguments and git's own stderr (cli/util/git.rs:25-31). Callers add context — `deno test --changed` wraps the rev-parse failure as \"`--changed` requires a git repository\" — so the underlying causes are repository state problems: not a repo, unborn branch with no commits, an unknown base ref for --changed=..., or detached/partial checkouts in release tooling.","triggerScenarios":"deno test --changed outside a git repo (`git rev-parse --show-toplevel` exits 128); --changed=<base> naming a ref that does not exist; a repo whose HEAD is unborn (no initial commit); git diff/ls-files failing on a corrupt index.","commonSituations":"Running --changed before the first commit; base branch renamed (master→main) leaving stale CI config; shallow clones missing the merge-base; git index locked by a concurrent process.","solutions":["Read the embedded stderr — it is git's own diagnostic and names the real problem.","For --changed outside a repo: git init && commit, or run plain `deno test` instead.","For --changed=<base>: confirm the ref exists (`git branch --list`, `git rev-parse <base>`) and update it (e.g. main vs master).","For a locked/corrupt index: ensure no other git process is running, then `git status` to surface index damage."],"exampleFix":"# before\n$ deno test --changed=master\nerror: `git diff --name-only master...HEAD` failed: fatal: ambiguous argument 'master...HEAD': unknown revision\n\n# after — use a ref that exists in this clone\ngit branch --list   # shows 'main'\ndeno test --changed=main","handlingStrategy":"validation","validationCode":"# Validate repo state before asking deno to diff it\ngit rev-parse --is-inside-work-tree >/dev/null || { echo 'not a git repo'; exit 1; }\ngit rev-parse --verify \"$BASE\" >/dev/null 2>&1 || { echo \"unknown base ref: $BASE\"; exit 1; }\ndeno test --changed=\"$BASE\"","typeGuard":null,"tryCatchPattern":"# Capture deno's exit and surface the embedded git stderr when it fails\nif ! out=$(deno test --changed 2>&1); then\n  echo \"$out\" | grep -A3 'git .* failed' || true\n  exit 1\nfi","preventionTips":["Make the initial commit before using --changed on a fresh repo.","Pin --changed to a ref you verified exists (main vs master renames bite often).","Treat the stderr embedded in the message as the source of truth — it is git's own diagnostic."],"tags":["git","test","changed","cli"],"backgroundTag":"git-command-failed","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}