{"record":{"id":"e0ca85eb7519ae2b","repo":"GitoxideLabs/gitoxide","slug":"state-label-is-already-saved","errorCode":null,"errorMessage":"{state_label} is already saved","messagePattern":"(.+?) is already saved","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/stash.rs","lineNumber":206,"sourceCode":"    pub name: gix::refs::FullName,\n    pub target: Target,\n    pub warning: Option<String>,\n}\n\n#[tracing::instrument(skip_all, fields(stash = %name))]\npub(super) fn save(\n    repository_path: &Path,\n    bare: bool,\n    workdir: &Path,\n    name: gix::refs::FullName,\n    message: String,\n    reflog_message: &'static str,\n    state_label: &'static str,\n) -> Result<SavedStash> {\n    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\")?;","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/stash.rs#L188-L224","documentation":"This error means a reference with the given name already exists in the repository, so the stash/state cannot be saved under that name. The library throws it before performing any edit, because saving would need `PreviousValue::MustNotExist` and a pre-existing ref would fail the ref-edit. It is a guard against silently overwriting an existing saved state.","triggerScenarios":"Calling save (e.g. via save_manual) with a `name` argument for which `repo.try_find_reference(name)` already resolves to an existing reference. Running the same named save twice without deleting or renaming the first one.","commonSituations":"Re-running a failed or interrupted workflow that had already saved the state under the same name; scripts hardcoding a fixed state name; users manually creating a ref that collides with the tool's state name.","solutions":["Choose a different, unique name for the saved state.","Delete the existing reference (e.g. `git update-ref -d <name>`) before saving again.","Check `try_find_reference` for existence first and branch on it instead of calling save unconditionally."],"exampleFix":"// before\nlet saved = save(repo_path, bare, \"my-stash\", message, ...)?;\n// after\nif try_state_exists(repo_path, bare, \"my-stash\")? {\n    eprintln!(\"my-stash already exists; picking a new name\");\n}\nlet saved = save(repo_path, bare, format!(\"my-stash-{timestamp}\"), message, ...)?;","handlingStrategy":"validation","validationCode":"let repo = gix::open(repo_path)?;\nif repo.try_find_reference(name.as_ref())?.is_some() {\n    // pick another name or delete the existing ref first\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().ends_with(\"is already saved\") => choose_new_name(),\n    other => other?,\n}","preventionTips":["Generate unique state names (include a timestamp or hash).","Check reference existence with try_find_reference before saving.","Treat named states as immutable and version the name when content changes."],"tags":["git","ref-already-exists","stash","conflict"],"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"}