nikivdev/code · error

git add -- <paths> failed with status {}

Error message

git add -- <paths> failed with status {}

What it means

Thrown when `git add -- <paths>` exits with a non-zero status after the library stages user-selected paths. Stdout/stderr are inherited, so the actual git diagnostics were already printed to the terminal; this error only records the exit status. It stops the interactive staging flow so a broken stage never proceeds to commit.

Source

Thrown at src/commit.rs:15222

        println!("done");
        return Ok(());
    }

    git_run_in(workdir, &["reset", "--quiet"])?;

    let mut cmd = Command::new("git");
    let status = cmd
        .current_dir(workdir)
        .arg("add")
        .arg("--")
        .args(stage_paths)
        .stdout(Stdio::inherit())
        .stderr(Stdio::inherit())
        .status()
        .context("failed to run git add for selected paths")?;

    if !status.success() {
        bail!("git add -- <paths> failed with status {}", status);
    }

    println!(
        "done ({} path{})",
        stage_paths.len(),
        if stage_paths.len() == 1 { "" } else { "s" }
    );

    Ok(())
}

fn split_paragraphs(message: &str) -> Vec<String> {
    let mut paragraphs = Vec::new();
    let mut current = Vec::new();

    for line in message.lines() {
        if line.trim().is_empty() {
            if !current.is_empty() {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Read the git diagnostics printed above the error (stderr was inherited) for the exact path problem
  2. Re-check file status with `git status` and re-select only existing files
  3. Remove a stale lock: delete `.git/index.lock` if no git process is running
  4. Confirm you are inside a git repository and the paths are relative to the repo root

Example fix

// before
if !status.success() {
    bail!("git add -- <paths> failed with status {}", status);
}
// after
if !status.success() {
    let remaining: Vec<_> = stage_paths.iter()
        .filter(|p| p.exists())
        .collect();
    bail!("git add -- <paths> failed with status {}; surviving paths: {:?}", status, remaining);
}
Defensive patterns

Strategy: validation

Validate before calling

// filter out vanished paths before staging
let existing: Vec<_> = stage_paths.iter().filter(|p| p.exists()).collect();
if existing.len() != stage_paths.len() {
    eprintln!("skipping {} missing paths", stage_paths.len() - existing.len());
}

Try / catch

match stage_selected_paths(&paths) {
    Err(e) if e.to_string().contains("git add") => {
        eprintln!("{e:#} — see git output above; check for deleted/renamed files");
    }
    Err(e) => eprintln!("{e:#}"),
    Ok(_) => {}
}

Prevention

When it happens

Trigger: Running `git add -- <selected paths>` when git exits non-zero: a path no longer exists (deleted/moved after selection), pathspec matches nothing, a file is ignored with --force semantics conflicting, or the index is locked.

Common situations: User selected files then deleted/renamed them before staging, staging inside a repo with a stale .git/index.lock, paths containing characters the shell/selection mangled, or calling outside a git work tree.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/5f9b3ed74e82fb7b. Report an issue: GitHub.