nikivdev/code · error
git {} failed: {}
Error message
git {} failed: {} What it means
git_capture_in runs a git command and captures stdout; on failure it bails with 'git <args> failed: <stderr>', appending git's trimmed stderr so the root cause is visible. Used by helpers that read git state from the colocated repo.
Source
Thrown at src/jj.rs:3404
.current_dir(repo_root)
.args(args)
.output()
.with_context(|| format!("failed to run jj {}", args.join(" ")))?;
if !output.status.success() {
bail!("jj {} failed", args.join(" "));
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
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 {}", args.join(" ")))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
bail!("git {} failed: {}", args.join(" "), stderr.trim());
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
fn jj_read_in(repo_root: &Path, args: &[&str]) -> Result<String> {
let output = Command::new("jj")
.current_dir(repo_root)
.args(["--at-op=@", "--ignore-working-copy"])
.args(args)
.output()
.with_context(|| format!("failed to run jj {}", args.join(" ")))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
bail!("jj {} failed: {}", args.join(" "), stderr.trim());
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
View on GitHub (pinned to a747e741ae)
Solutions
- Read the appended stderr to identify the failing git operation and fix that cause.
- Confirm you are inside the repo: `git rev-parse --git-dir` succeeds from the working directory.
- If the repo is mid-operation or corrupt, run `f git-repair` or `git status` to diagnose.
Example fix
// before flow fetch # git for-each-ref fails on bad refspec // after git rev-parse --git-dir # verify repo f git-repair # if mid-operation flow fetch
Defensive patterns
Strategy: try-catch
Validate before calling
// shell
git rev-parse --git-dir >/dev/null 2>&1 || { echo "not inside a git repo" >&2; exit 1; } Try / catch
match flow_command() {
Err(e) if e.starts_with("git ") && e.contains("failed: ") => {
let stderr = e.split("failed: ").nth(1).unwrap_or("");
eprintln("git failed: {stderr}");
Err(e)
}
other => other,
} Prevention
- Run flow commands from inside the repo working tree.
- Keep git installed and on PATH; check `git --version` in CI images.
- Resolve interrupted git operations before running flow.
When it happens
Trigger: Any git invocation via git_capture_in (e.g. rev-parse, status plumbing, for-each-ref) exits non-zero — run outside a git repo, unknown ref/object, or corrupted index.
Common situations: Running the tool outside a git/jj colocated repo; referencing a branch deleted on the remote; git hooks or fsck issues corrupting operations.
Related errors
- git {} failed
- {} failed with status {}
- Lin.app is not running
- pbcopy exited with status {}
- AI task '{}' failed with status {}
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/130b9bbd50131fba.
Report an issue: GitHub.