{"record":{"id":"2b0a2ccfc9ff8617","repo":"GitoxideLabs/gitoxide","slug":"git-stash-push-failed","errorCode":null,"errorMessage":"git stash push failed: {}","messagePattern":"git stash push failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/stash.rs","lineNumber":221,"sourceCode":"    let repo = open_repository(repository_path, bare, false)\n        .with_context(|| format!(\"could not open repository to save {state_label}\"))?;\n    if repo.try_find_reference(name.as_ref())?.is_some() {\n        anyhow::bail!(\"{state_label} is already saved\");\n    }\n    let previous = repo\n        .try_find_reference(\"refs/stash\")?\n        .and_then(|mut reference| reference.peel_to_id().ok().map(gix::Id::detach));\n    drop(repo);\n\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(workdir)\n        .args([\"stash\", \"push\", \"--include-untracked\", \"--quiet\", \"--message\"])\n        .arg(message)\n        .output()\n        .context(\"could not launch git stash push\")?;\n    if !output.status.success() {\n        anyhow::bail!(\"git stash push failed: {}\", output.stderr.trim().to_str_lossy());\n    }\n\n    let repo = open_repository(repository_path, bare, false).context(\"could not reopen repository after stashing\")?;\n    let mut stash = repo\n        .try_find_reference(\"refs/stash\")?\n        .context(\"git stash push did not create refs/stash\")?;\n    let id = stash.peel_to_id()?.detach();\n    if previous == Some(id) {\n        anyhow::bail!(\"git stash push did not create a new stash\");\n    }\n    let target = Target::Object(id);\n    if let Err(err) = repo.edit_references([RefEdit::update(\n        name.clone(),\n        target.clone(),\n        PreviousValue::MustNotExist,\n        reflog_message,\n    )]) {\n        drop(repo);","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/stash.rs#L203-L239","documentation":"The external `git stash push --include-untracked --quiet --message` subprocess exited with a non-zero status, so the library aborts the save. The stderr of the git invocation is included in the message. This means the actual stash operation failed before the library could create the named reference.","triggerScenarios":"Calling save/save_manual, which shells out to `git stash push`; the child process returns non-zero (e.g. nothing to stash in some git configs, lock files, index corruption, git not agreeing to the operation).","commonSituations":"Another git process holding `.git/index.lock`; a git version whose `stash push` rejects the invocation; dirty submodule/permission problems making stash fail; git binary missing or broken.","solutions":["Read the stderr in the error message and fix the underlying git failure it reports.","Remove stale lock files (`.git/index.lock`) left by crashed git processes.","Run `git stash push --include-untracked` manually in the repo to reproduce and diagnose.","Ensure a compatible `git` binary is installed and on PATH."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check for common blockers\nif repo.workdir().map(|w| w.join(\".git/index.lock\").exists()).unwrap_or(false) {\n    return Err(anyhow!(\"index.lock present; another git process may be running\"));\n}","typeGuard":null,"tryCatchPattern":"match save(repo_path, bare, name, msg, reflog) {\n    Err(e) if e.to_string().contains(\"git stash push failed\") => {\n        eprintln!(\"git stderr: inspect the chained message\");\n    }\n    other => other?,\n}","preventionTips":["Ensure no concurrent git operations hold .git/index.lock.","Keep a supported `git` binary on PATH.","Run `git stash push --include-untracked` manually first when automating unfamiliar repos."],"tags":["git","subprocess","stash","command-failed"],"backgroundTag":"git-command-failed","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}