nikivdev/code · error
git {} failed
Error message
git {} failed What it means
git_capture_in runs a git command in the repo root and captures stdout; a non-zero exit status produces this bail with the joined arguments. Used by prepare_source_workspace to inspect the colocated git side of the source workspace.
Source
Thrown at src/ext.rs:405
let output = Command::new("jj")
.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() {
bail!("git {} failed", args.join(" "));
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
fn prompt_yes_no(message: &str, default_yes: bool) -> Result<bool> {
let prompt = if default_yes { "[Y/n]" } else { "[y/N]" };
print!("{message} {prompt}: ");
io::stdout().flush()?;
if !io::stdin().is_terminal() {
bail!("Non-interactive session; cannot confirm action.");
}
let mut input = String::new();
io::stdin().read_line(&mut input)?;
let answer = input.trim().to_ascii_lowercase();
if answer.is_empty() {
return Ok(default_yes);
}
Ok(answer == "y" || answer == "yes")View on GitHub (pinned to a747e741ae)
Solutions
- Run the same git command manually in the source repo to see the real git error.
- Ensure git is installed and on PATH (`git --version`).
- If the source lacks .git, recreate the workspace with `jj git init --colocate`.
Example fix
// before let out = git_capture_in(&repo_root, &["status", "--porcelain"])?; // after (shell diagnosis first) // cd <source> && git status --porcelain # observe the actual git error let out = git_capture_in(&repo_root, &["status", "--porcelain"])?;
Defensive patterns
Strategy: validation
Validate before calling
if std::process::Command::new("git").arg("--version").output().map(|o| !o.status.success()).unwrap_or(true) {
return Err(anyhow!("git is not installed or not functioning"));
}
if !source.join(".git").exists() {
return Err(anyhow!("{} has no .git; recreate with `jj git init --colocate`", source));
} Try / catch
if let Err(e) = import_external_path(source) {
if e.to_string().starts_with("git ") {
eprintln!("git step failed ({e}); run the same git command in the source repo to diagnose");
} else { return Err(e.into()); }
} Prevention
- Install git in minimal/CI images that use this tool.
- Create source workspaces with --colocate so git commands succeed.
- Check git version supports the flags the tool passes.
When it happens
Trigger: git binary missing from PATH; running a git command outside a git repository (source jj repo is not colocated); invalid arguments or git hooks failing during the queried operation.
Common situations: Importing a jj workspace created without --colocate (no .git); minimal containers/CI images without git installed; git version too old for the flags used.
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/0706bf090001baba.
Report an issue: GitHub.