{"record":{"id":"8ac40657f282e981","repo":"gitbutlerapp/gitbutler","slug":"cannot-unapply-branch-branch-from-an-ad-hoc-wo-8ac406","errorCode":null,"errorMessage":"Cannot unapply branch '{branch}' from an ad-hoc workspace because non-tip branches can only disappear if their now removed metadata disambiguated them","messagePattern":"Cannot unapply branch '(.+?)' from an ad-hoc workspace because non-tip branches can only disappear if their now removed metadata disambiguated them","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":266,"sourceCode":"            bail!(\"Cannot unapply a branch from an ad-hoc detached workspace\");\n        };\n        let mut ws_md = meta.workspace(workspace_ref_name.as_ref())?;\n        if ws.kind.has_managed_ref() || ws.has_metadata() {\n            ws.reconcile_metadata(&mut ws_md)?;\n        }\n        let branch_removed_from_ws_meta = ws_md.unapply_branch(branch);\n        if !branch_removed_from_ws_meta {\n            // The branch wasn't in workspace metadata, yet it was present, so also delete its branch metadata\n            // as it could be used to disambiguate the segment.\n            // TODO: this will actually be observable even if it doens't work, unless it's run in a transaction, which right now it's not!\n            //       Should be able to redo the traversal with an overlay that hides branch metadata, but I'd say it's not important enough.\n            meta.remove(branch)?;\n            let graph = ws\n                .graph\n                .redo_traversal_with_overlay(repo, meta, Overlay::default())?;\n            let workspace = graph.into_workspace()?;\n            if workspace.refname_is_segment(branch) {\n                bail!(\n                    \"Cannot unapply branch '{branch}' from an ad-hoc workspace because non-tip branches can only disappear if their now removed metadata disambiguated them\",\n                    branch = branch.shorten()\n                );\n            }\n            return Ok(Outcome::new(Cow::Owned(workspace)));\n        }\n\n        // Everything past this point is stricly in non-dry-run mode and we may totally end up in intermediate states\n        // if something fails.\n        // Redo the traversal with the changed workspace metadata so code below can rely on the reconciled version.\n        let ws = ws\n            .graph\n            .redo_traversal_with_overlay(\n                repo,\n                meta,\n                Overlay::default()\n                    .with_dropped_references([branch.to_owned()])\n                    .with_workspace_metadata_override(Some((","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L248-L284","documentation":"In ad-hoc workspaces, removing a non-tip branch normally only works if deleting its metadata (e.g. assigned-branch name) made it merge/disambiguate into another segment. If after metadata removal and graph re-traversal the branch is still its own segment, the ad-hoc workspace cannot dissolve it and unapply aborts.","triggerScenarios":"Calling `unapply` on a branch inside an ad-hoc workspace that sits below the tip of its stack (non-tip), where the branch removal path relies on `meta.remove(branch)` + overlay re-traversal, and the re-computed workspace still contains the branch as a segment.","commonSituations":"Unapplying a middle-of-stack branch in an ad-hoc (unnamed) workspace; stacks where sibling branches would remain ambiguous without managed metadata.","solutions":["Unapply the branch from a named/managed workspace instead, where explicit reference surgery is supported","Reorder/rebase so the target branch becomes the tip of its stack before unapply","Squash or merge the branch's commits into its parent so the segment legitimately disappears"],"exampleFix":"// before\nunapply(repo, meta, &adhoc_ws, middle_branch, ...)?; // fails for non-tip\n// after\nlet ws = ensure_named_workspace(repo, meta)?; // managed workspace\nunapply(repo, meta, &ws, middle_branch, ...)?;","handlingStrategy":"validation","validationCode":"fn is_unapplyable(ws: &Workspace, branch: &gix::refs::FullNameRef) -> bool {\n    !matches!(ws.kind, but_graph::workspace::WorkspaceKind::AdHoc)\n        || ws.refname_is_segment_at_tip(branch)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict ad-hoc workspace unapply to tip branches","Use managed (named) workspaces for mid-stack branch removal"],"tags":["git","workspace","ad-hoc","stack"],"backgroundTag":"unsupported-operation","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"}