{"record":{"id":"5a056b5b2b48f008","repo":"GitoxideLabs/gitoxide","slug":"already-has-saved-worktree-state","errorCode":null,"errorMessage":"{} already has saved worktree state","messagePattern":"(.+?) already has saved worktree state","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/stash.rs","lineNumber":143,"sourceCode":"    let head = repo\n        .head_id()\n        .context(\"stashing changes requires a born HEAD\")?\n        .detach();\n    if head != id {\n        anyhow::bail!(\"changes can only be stashed at the current HEAD\");\n    }\n    if repo\n        .index_or_empty()\n        .context(\"could not inspect the index before stashing\")?\n        .entries()\n        .iter()\n        .any(|entry| entry.stage() != gix::index::entry::Stage::Unconflicted)\n    {\n        anyhow::bail!(\"cannot stash changes with unresolved index conflicts\");\n    }\n    let name = reference(id)?;\n    if repo.try_find_reference(name.as_ref())?.is_some() {\n        anyhow::bail!(\"{} already has saved worktree state\", id.to_hex_with_len(7));\n    }\n    drop(repo);\n    if !super::review::is_dirty(&workdir)? {\n        anyhow::bail!(\"there are no worktree or index changes to stash\");\n    }\n    let saved = save(\n        repository_path,\n        bare,\n        &workdir,\n        name,\n        format!(\"tix {}\", id.to_hex_with_len(7)),\n        \"tix commit stash\",\n        \"commit state\",\n    )?;\n    let mut notice = format!(\"stashed changes at {}\", id.to_hex_with_len(7));\n    if let Some(warning) = saved.warning {\n        write!(notice, \"; {warning}\").expect(\"writing to a string cannot fail\");\n    }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/stash.rs#L125-L161","documentation":"A tix stash reference is named after the commit at which state was saved, so at most one saved worktree state can exist per commit. This error fires when `save_manual` finds an existing reference under that commit's stash name, meaning a stash already exists for this commit and creating another would overwrite it. It reports the short hash of the commit.","triggerScenarios":"Calling `stash::save_manual` twice at the same HEAD commit without restoring/deleting the first stash; restoring a repo where an earlier tix stash session left a reference for the current HEAD.","commonSituations":"Repeated `tix stash` at the same commit; forgetting a previous stash after a failed restore; re-running a script that stashes idempotently.","solutions":["Restore (`unstash`) the existing saved state first, then make the new stash","Delete the existing stash reference if its saved state is no longer needed","Check for an existing stash (e.g. via `find`/`try_find_reference` with `reference(id)`) before saving"],"exampleFix":"// before blind re-stash\nstash::save_manual(path, bare, workdir, head_id)?;\n// after: clear existing stash for this commit first\nlet name = tix::edit::stash::reference(head_id)?;\nif repo.try_find_reference(name.as_ref())?.is_some() {\n    tix::edit::stash::restore_manual(path, bare, head_id)?;\n}\nstash::save_manual(path, bare, workdir, head_id)?;","handlingStrategy":"validation","validationCode":"let name = tix::edit::stash::reference(id)?;\nlet repo = gix::open(path)?;\nlet exists = repo.try_find_reference(name.as_ref())?.is_some();\nif exists {\n    anyhow::bail!(\"a stash already exists for {}; restore or delete it first\", id);\n}","typeGuard":"fn has_saved_state(repo: &gix::Repository, id: ObjectId) -> bool {\n    let name = tix::edit::stash::reference(id).expect(\"valid id\");\n    repo.try_find_reference(name.as_ref()).map(|r| r.is_some()).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Check for an existing stash reference before every save","Always restore or delete a stash before stashing the same commit again","Avoid re-running stash scripts without cleanup logic"],"tags":["git","references","stash","duplicate"],"backgroundTag":"file-already-exists","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}