nikivdev/code · error
git {} failed in {}
Error message
git {} failed in {} What it means
Raised by the shared git command helper when a `git <subcommand>` invocation exits with a non-zero status in the given repo root. The message includes the exact git args and repo path so the failing operation can be reproduced. It indicates git ran but rejected the operation (bad ref, not a repo, dirty index, etc.).
Source
Thrown at src/pr_preview.rs:1542
fn git_rev_parse(repo_root: &Path, rev: &str) -> Result<String> {
git_capture_in(repo_root, &["rev-parse", "--verify", "--quiet", rev])
}
fn git_capture_in(repo_root: &Path, args: &[&str]) -> Result<String> {
let output = Command::new("git")
.current_dir(repo_root)
.args(args)
.output()
.with_context(|| {
format!(
"failed to run git {} in {}",
args.join(" "),
repo_root.display()
)
})?;
if !output.status.success() {
bail!("git {} failed in {}", args.join(" "), repo_root.display());
}
Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
}
fn git_capture_for_preview(
repo_root: &Path,
work_tree_root: Option<&Path>,
args: &[&str],
) -> Result<String> {
let mut command = Command::new("git");
if let Some(work_tree_root) = work_tree_root {
command
.arg("--git-dir")
.arg(repo_root.join(".git"))
.arg("--work-tree")
.arg(work_tree_root)
.current_dir(work_tree_root);
} else {View on GitHub (pinned to a747e741ae)
Solutions
- Re-run the exact `git <args>` shown in the message inside the reported repo root to see git's own error.
- Verify the directory is a git repo: `git -C <repo_root> rev-parse --is-inside-work-tree`.
- Check that the referenced branch/ref/commit exists (`git branch -a`, `git rev-parse <ref>`).
- Remove a stale lock if present: delete .git/index.lock only when no git process is running.
Defensive patterns
Strategy: try-catch
Validate before calling
// verify repo before calling
if !repo_root.join(".git").exists() {
return Err(anyhow!("{} is not a git repository", repo_root.display()));
} Try / catch
match run_git(repo_root, &["rev-parse", "HEAD"]) {
Ok(sha) => sha,
Err(e) => {
eprintln!("git unavailable in {}: {e}", repo_root.display());
return Err(e);
}
} Prevention
- Confirm the target directory is a git repo before running preview.
- Validate referenced branches/refs exist before passing them to git.
- Capture and log git stderr to make failures diagnosable.
- Watch for stale .git/index.lock files in CI.
When it happens
Trigger: Any git command routed through this helper (e.g. `git rev-parse`, `git diff`, `git log`) failing: repo_root is not a git repository, a requested branch/commit SHA does not exist, or git's stderr reports a merge conflict or lock error.
Common situations: Running the preview in a directory without .git, referencing a branch that was deleted or renamed, a detached HEAD with no upstream, or a .git/index.lock left by a crashed git process.
Related errors
- Lin.app is not running
- failed to stash working tree: {}
- git status failed with {}
- git add failed with {}
- git commit failed with {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/0344dc7e843de3db.
Report an issue: GitHub.