{"record":{"id":"1e2d712d74a379f6","repo":"gitbutlerapp/gitbutler","slug":"cannot-unapply-workspace-reference-without-sw","errorCode":null,"errorMessage":"Cannot unapply workspace reference '{}' without switching away from it","messagePattern":"Cannot unapply workspace reference '(.+?)' without switching away from it","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":471,"sourceCode":"\n    /// Unapply the managed workspace reference itself.\n    ///\n    /// - Run before normal branch removal because the workspace ref is a container, not a stack segment.\n    /// - Reject dispositions that keep the workspace ref because unapplying it requires switching away.\n    /// - Pick a named checkout target from the current projection.\n    /// - Reject GitButler-conflicted target commits with a ref-aware error.\n    /// - Safely checkout the target commit, then switch `HEAD` to the target ref.\n    /// - Optionally delete the managed workspace ref and metadata.\n    /// - Retraverse from the target ref so the returned workspace matches the new `HEAD`.\n    fn unapply_workspace_reference(\n        ws: &but_graph::Workspace,\n        repo: &gix::Repository,\n        meta: &mut impl RefMetadata,\n        workspace_ref_name: &FullNameRef,\n        disposition: WorkspaceDisposition,\n    ) -> anyhow::Result<Outcome<'static>> {\n        if !disposition.may_switch_away_from_workspace() {\n            bail!(\n                \"Cannot unapply workspace reference '{}' without switching away from it\",\n                workspace_ref_name.shorten()\n            );\n        }\n\n        let ref_to_checkout = ref_to_checkout_after_workspace_unapply(ws)?;\n        safe_checkout_ref_to_checkout(\n            repo,\n            &ref_to_checkout,\n            but_core::worktree::checkout::Options {\n                skip_head_update: true,\n                ..Default::default()\n            },\n        )?;\n\n        let workspace_ref_expected = ws\n            .tip_commit()\n            .context(\"BUG: unborn should be impossible here\")?","sourceCodeStart":453,"sourceCodeEnd":489,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L453-L489","documentation":"`unapply_workspace_reference` refuses to remove the currently checked-out workspace reference unless the caller explicitly declared, via `WorkspaceDisposition`, that it is allowed to switch the worktree away to another commit. This prevents silently changing what HEAD points at.","triggerScenarios":"Calling unapply on the workspace branch itself while `disposition.may_switch_away_from_workspace()` returns false (e.g. default/strict disposition passed by the caller).","commonSituations":"Tooling that wants to dissolve an entire workspace but hasn't opted into switching the user's checkout; automated pipelines running unapply against the active workspace ref.","solutions":["Pass a `WorkspaceDisposition` that permits switching away from the workspace (e.g. the variant with `may_switch_away_from_workspace: true`)","Unapply only non-workspace branches, keeping the workspace reference intact","Switch to another branch first if using a strict disposition is intentional"],"exampleFix":"// before\nunapply_workspace_reference(ws, repo, meta, ws_ref, WorkspaceDisposition::default())?;\n// after\nlet disposition = WorkspaceDisposition { may_switch_away_from_workspace: true, .. };\nunapply_workspace_reference(ws, repo, meta, ws_ref, disposition)?;","handlingStrategy":"validation","validationCode":"let disposition = WorkspaceDisposition { may_switch_away_from_workspace: true, .. };\nunapply_workspace_reference(ws, repo, meta, ws_ref, disposition)?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always decide explicitly whether unapplying the workspace ref may switch the checkout","Never use Default dispositions when dissolving whole workspaces"],"tags":["git","workspace","checkout","guard"],"backgroundTag":"invalid-argument-value","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}