GitoxideLabs/gitoxide · error · anyhow::Error

git add for resolved paths failed with

Error message

git add for resolved paths failed with {}: {stderr}

What it means

Same as the bare variant: the external `git add` for resolved paths failed, but here stderr was non-empty and is appended to the message so the git CLI's own diagnostic is shown. It surfaces the underlying reason `git add` rejected the paths.

Solutions

  1. Read the stderr portion of the message and fix the underlying git add cause it names.
  2. Remove a stale .git/index.lock if no git process is running.
  3. Re-check that the resolved paths still exist before staging.
  4. Run the identical `git add` command manually in the repo to reproduce and diagnose.

Example fix

// before
anyhow::bail!("git add for resolved paths failed with {}: {stderr}", output.status);
// after
anyhow::bail!("git add for resolved paths failed with {}: {stderr}", output.status)
    .context(format!("paths: {:?}", resolved_paths));
Defensive patterns

Strategy: try-catch

Validate before calling

for p in &resolved_paths { if !p.exists() { bail!("path missing: {}", p.display()); } }

Try / catch

match stage_resolved_paths(repo, &paths) {
    Err(err) => {
        let msg = err.to_string();
        if let Some(stderr) = msg.split("failed with ").nth(1) {
            eprintln!("git said: {stderr}");
        }
        return Err(err);
    }
}

Prevention

When it happens

Trigger: Spawned `git add -- <resolved paths>` exits non-zero and prints a diagnostic, e.g. 'pathspec did not match any files', index.lock contention, or permission errors on the index.

Common situations: Resolved path no longer exists on disk when staging; concurrent git operation holding .git/index.lock; pathspec quoting issues with special characters in filenames.

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 GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/ff9224c12becfef1. Report an issue: GitHub.

Appendix: source

Thrown at gix-tix/src/lib.rs:5644

        .context("cannot resolve a conflict without a worktree")?;
    let mut command = Command::new("git");
    command
        .arg("--literal-pathspecs")
        .arg("-C")
        .arg(workdir)
        .args(["add", "-A", "--"]);
    for path in &paths {
        command.arg(gix::path::from_bstr(path.as_bstr()).as_ref());
    }
    let output = command
        .output()
        .context("could not launch git add for resolved paths")?;
    if !output.status.success() {
        let stderr = output.stderr.trim().to_str_lossy();
        if stderr.is_empty() {
            anyhow::bail!("git add for resolved paths failed with {}", output.status);
        }
        anyhow::bail!("git add for resolved paths failed with {}: {stderr}", output.status);
    }

    let index = repository
        .open_index()
        .context("could not verify the resolved conflict index")?;
    if index
        .entries()
        .iter()
        .any(|entry| entry.stage() != gix::index::entry::Stage::Unconflicted)
    {
        anyhow::bail!("the conflict index still has unresolved entries");
    }
    Ok(())
}

fn preview_todo_rebase_conflict(
    app: &mut App,
    conflict: &edit::rebase::PlanConflict,

View on GitHub (pinned to e73179060b)