{"record":{"id":"e9a2c40faf1f557a","repo":"GitoxideLabs/gitoxide","slug":"cannot-delete-the-checked-out-branch-without-selec","errorCode":null,"errorMessage":"cannot delete the checked-out branch without selecting another checkout","messagePattern":"cannot delete the checked-out branch without selecting another checkout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/edit/rebase.rs","lineNumber":2214,"sourceCode":"        for transition in &transitions {\n            super::forget::preflight_tree_transition(\n                &transition.repo,\n                &transition.workdir,\n                transition.old,\n                transition.new,\n            )?;\n        }\n        let head = self.repo.head()?;\n        let unborn = head.is_unborn();\n        let current_ref = head.referent_name().map(ToOwned::to_owned);\n        let mut deferred_ref_deletions = Vec::new();\n        if let (Some(expected_refs), Some(current_ref)) = (&mut self.expected_refs, current_ref) {\n            if expected_refs\n                .iter()\n                .any(|expected| expected.name == current_ref && expected.old.is_some() && expected.new.is_none())\n                && (self.repo.workdir().is_none() || (self.selected.is_none() && !self.checkout_after_finish))\n            {\n                anyhow::bail!(\"cannot delete the checked-out branch without selecting another checkout\");\n            }\n            expected_refs.retain(|expected| {\n                let defer = expected.name == current_ref && expected.old.is_some() && expected.new.is_none();\n                if defer {\n                    deferred_ref_deletions.push((expected.name.clone(), expected.old.expect(\"checked above\")));\n                }\n                !defer\n            });\n        }\n        let updated_refs = update_refs(\n            &self.repo,\n            &self.rewritten,\n            unborn,\n            self.selected,\n            &self.committer,\n            self.expected_refs.take(),\n            (&self.pins, &self.delete_refs),\n            resource_edits,","sourceCodeStart":2196,"sourceCodeEnd":2232,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/edit/rebase.rs#L2196-L2232","documentation":"A ref-update batch tried to delete the currently checked-out branch while the session had neither selected another checkout nor requested a checkout after finish (or the repo is bare). Deleting HEAD's branch would leave HEAD dangling, so the update is rejected before applying deletions.","triggerScenarios":"Calling the rebase/ref-edit session with a deletion of the branch that `HEAD` points to, with `self.selected == None` and `checkout_after_finish == false` in a worktree repo, or any such deletion in a bare repo where checkout re-selection is impossible.","commonSituations":"Automation pruning 'stale' branches that unknowingly includes the checked-out one; scripts deleting the feature branch right after rebasing while still on it; deleting branches parsed from an unfiltered ref list.","solutions":["Select another branch/commit for checkout (`selected`) before deleting the current branch","Set `checkout_after_finish = true` so the tool moves HEAD off the branch first","Skip the branch currently pointed at by HEAD in the deletion list"],"exampleFix":"// before\nsession.delete_ref(current_branch)?;\n// after\nif current_branch == repo.head_branch() {\n    session.select_checkout(other_branch);\n}\nsession.delete_ref(current_branch)?;","handlingStrategy":"validation","validationCode":"fn deletion_is_safe(head_branch: &RefName, targets: &[RefName], selected: Option<&RefName>, checkout_after_finish: bool, bare: bool) -> bool {\n    !targets.contains(&head_branch) || selected.is_some() || checkout_after_finish || bare == false && false\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"checked-out branch\") => {\n        eprintln!(\"select another checkout or enable checkout-after-finish before deleting HEAD's branch\");\n    }\n    r => r?,\n}","preventionTips":["Exclude the HEAD branch from automated pruning lists","Always provide an alternate checkout when deleting the current branch","Filter ref lists against repo.head_branch() before batch deletion"],"tags":["branch","head","ref-delete","checkout"],"backgroundTag":"invalid-state-transition","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"}