{"record":{"id":"5f9b3ed74e82fb7b","repo":"nikivdev/code","slug":"git-add-paths-failed-with-status","errorCode":null,"errorMessage":"git add -- <paths> failed with status {}","messagePattern":"git add -- <paths> failed with status (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":15222,"sourceCode":"        println!(\"done\");\n        return Ok(());\n    }\n\n    git_run_in(workdir, &[\"reset\", \"--quiet\"])?;\n\n    let mut cmd = Command::new(\"git\");\n    let status = cmd\n        .current_dir(workdir)\n        .arg(\"add\")\n        .arg(\"--\")\n        .args(stage_paths)\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .context(\"failed to run git add for selected paths\")?;\n\n    if !status.success() {\n        bail!(\"git add -- <paths> failed with status {}\", status);\n    }\n\n    println!(\n        \"done ({} path{})\",\n        stage_paths.len(),\n        if stage_paths.len() == 1 { \"\" } else { \"s\" }\n    );\n\n    Ok(())\n}\n\nfn split_paragraphs(message: &str) -> Vec<String> {\n    let mut paragraphs = Vec::new();\n    let mut current = Vec::new();\n\n    for line in message.lines() {\n        if line.trim().is_empty() {\n            if !current.is_empty() {","sourceCodeStart":15204,"sourceCodeEnd":15240,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L15204-L15240","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the git diagnostics printed above the error (stderr was inherited) for the exact path problem","Re-check file status with `git status` and re-select only existing files","Remove a stale lock: delete `.git/index.lock` if no git process is running","Confirm you are inside a git repository and the paths are relative to the repo root"],"exampleFix":"// before\nif !status.success() {\n    bail!(\"git add -- <paths> failed with status {}\", status);\n}\n// after\nif !status.success() {\n    let remaining: Vec<_> = stage_paths.iter()\n        .filter(|p| p.exists())\n        .collect();\n    bail!(\"git add -- <paths> failed with status {}; surviving paths: {:?}\", status, remaining);\n}","handlingStrategy":"validation","validationCode":"// filter out vanished paths before staging\nlet existing: Vec<_> = stage_paths.iter().filter(|p| p.exists()).collect();\nif existing.len() != stage_paths.len() {\n    eprintln!(\"skipping {} missing paths\", stage_paths.len() - existing.len());\n}","typeGuard":null,"tryCatchPattern":"match stage_selected_paths(&paths) {\n    Err(e) if e.to_string().contains(\"git add\") => {\n        eprintln!(\"{e:#} — see git output above; check for deleted/renamed files\");\n    }\n    Err(e) => eprintln!(\"{e:#}\"),\n    Ok(_) => {}\n}","preventionTips":["Re-run `git status` after user selection and before staging to drop vanished files","Remove stale `.git/index.lock` if no git process is running","Ensure paths are repo-relative and properly escaped","Check for newline/space mangling in path lists (-- paths are safe, shell lists are not)"],"tags":["git","staging","external-process"],"backgroundTag":"git-command-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}