{"record":{"id":"4c508a2a0d2e1acc","repo":"GitoxideLabs/gitoxide","slug":"git-stash-push-did-not-create-a-new-stash","errorCode":null,"errorMessage":"git stash push did not create a new stash","messagePattern":"git stash push did not create a new stash","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/stash.rs","lineNumber":230,"sourceCode":"\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);\n        let restore = Command::new(\"git\")\n            .arg(\"-C\")\n            .arg(workdir)\n            .args([\"stash\", \"pop\", \"--index\", \"--quiet\"])\n            .output();\n        return Err(anyhow::anyhow!(err)).context(match restore {\n            Ok(output) if output.status.success() => {\n                format!(\"could not retain {state_label}; original state was restored\")\n            }","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/stash.rs#L212-L248","documentation":"After running `git stash push`, `refs/stash` still points to the same commit it had before, meaning the stash operation silently did not create a new stash entry. The library detects this by comparing the pre-push `refs/stash` id with the post-push id and bails. This protects against editing the named state reference to point at a stale/unchanged stash commit.","triggerScenarios":"Calling save/save_manual when `git stash push` exits 0 but does not actually stash anything new (e.g. nothing to stash behavior, or the stash ref was manually reset), so `previous == Some(id)`.","commonSituations":"A clean working tree where git reports 'No local changes to save' yet exits successfully; hooks or config altering stash behavior; a previous stash push having already consumed the changes.","solutions":["Verify the working tree actually has uncommitted changes before saving.","Inspect `git stash list` and `git rev-parse refs/stash` to see why the ref did not move.","If the changes were already stashed, skip save or resume from the existing state instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only save when there is something to stash\nlet dirty = !repo.status(gix::status::platform::prepare::Options::default())?.is_empty();\nif !dirty { return Ok(()); } // nothing to stash; skip save","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"did not create a new stash\") => {\n        // treat as no-op: working tree was clean\n    }\n    other => other?,\n}","preventionTips":["Check for uncommitted changes before invoking stash-based save.","Do not manually reset refs/stash while the flow is running.","Log `git rev-parse refs/stash` before and after to detect no-op pushes."],"tags":["git","stash","invariant-violation","state-consistency"],"backgroundTag":"internal-invariant-violation","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"}