gitbutlerapp/gitbutler · error

Cannot unapply branch

Error message

Cannot unapply branch '{branch}' from an ad-hoc workspace because non-tip branches can only disappear if their now removed metadata disambiguated them

What it means

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.

Solutions

  1. Unapply the branch from a named/managed workspace instead, where explicit reference surgery is supported
  2. Reorder/rebase so the target branch becomes the tip of its stack before unapply
  3. Squash or merge the branch's commits into its parent so the segment legitimately disappears

Example fix

// before
unapply(repo, meta, &adhoc_ws, middle_branch, ...)?; // fails for non-tip
// after
let ws = ensure_named_workspace(repo, meta)?; // managed workspace
unapply(repo, meta, &ws, middle_branch, ...)?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_unapplyable(ws: &Workspace, branch: &gix::refs::FullNameRef) -> bool {
    !matches!(ws.kind, but_graph::workspace::WorkspaceKind::AdHoc)
        || ws.refname_is_segment_at_tip(branch)
}

Prevention

When it happens

Trigger: 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.

Common situations: Unapplying a middle-of-stack branch in an ad-hoc (unnamed) workspace; stacks where sibling branches would remain ambiguous without managed metadata.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/8ac40657f282e981. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/branch/unapply.rs:266

            bail!("Cannot unapply a branch from an ad-hoc detached workspace");
        };
        let mut ws_md = meta.workspace(workspace_ref_name.as_ref())?;
        if ws.kind.has_managed_ref() || ws.has_metadata() {
            ws.reconcile_metadata(&mut ws_md)?;
        }
        let branch_removed_from_ws_meta = ws_md.unapply_branch(branch);
        if !branch_removed_from_ws_meta {
            // The branch wasn't in workspace metadata, yet it was present, so also delete its branch metadata
            // as it could be used to disambiguate the segment.
            // 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!
            //       Should be able to redo the traversal with an overlay that hides branch metadata, but I'd say it's not important enough.
            meta.remove(branch)?;
            let graph = ws
                .graph
                .redo_traversal_with_overlay(repo, meta, Overlay::default())?;
            let workspace = graph.into_workspace()?;
            if workspace.refname_is_segment(branch) {
                bail!(
                    "Cannot unapply branch '{branch}' from an ad-hoc workspace because non-tip branches can only disappear if their now removed metadata disambiguated them",
                    branch = branch.shorten()
                );
            }
            return Ok(Outcome::new(Cow::Owned(workspace)));
        }

        // Everything past this point is stricly in non-dry-run mode and we may totally end up in intermediate states
        // if something fails.
        // Redo the traversal with the changed workspace metadata so code below can rely on the reconciled version.
        let ws = ws
            .graph
            .redo_traversal_with_overlay(
                repo,
                meta,
                Overlay::default()
                    .with_dropped_references([branch.to_owned()])
                    .with_workspace_metadata_override(Some((

View on GitHub (pinned to 58e5313667)