gitbutlerapp/gitbutler · error

Ad-hoc (single-branch) branch moves are not supported…

Error message

Ad-hoc (single-branch) branch moves are not supported inside transactions

What it means

`Transaction::stack_branch_on` refuses ad-hoc (single-branch, no workspace metadata / branch-stack-order) branch moves: after computing the rebase outcome it ensures both new_tip and branch_stack_order are Some, failing otherwise. Inside a transaction, only proper stacked-workspace branch moves are allowed.

Solutions

  1. Perform the ad-hoc branch move outside a transaction using the direct branch-manipulation APIs in but-workspace/but-core
  2. Ensure the branch belongs to a workspace stack so branch_stack_order is computed
  3. Reassign or initialize the workspace for the branch before stacking operations inside the transaction
  4. Restructure automation so stack moves happen via the stack API and single-branch moves via plain rebase

Example fix

// before
let mut tx = repo.transaction()?;
tx.stack_branch_on(&adhoc_branch, &target)?; // errors for ad-hoc branch
// after
let mut tx = repo.transaction()?;
tx.stack_branch_on(&stacked_branch, &target)?; // branch must be in a stack
// or for ad-hoc: but_workspace::branch::move_direct(...)
Defensive patterns

Strategy: validation

Validate before calling

// only call stack_branch_on for branches managed in a workspace stack
let is_stacked = workspace.stacks.iter()
    .any(|s| s.branches.iter().any(|b| b.ref_name == branch.ref_name));
if !is_stacked { return Err(anyhow!("use non-transactional move for ad-hoc branch")); }

Try / catch

match tx.stack_branch_on(&branch, &onto) {
    Err(e) if format!("{e:#}").contains("Ad-hoc (single-branch) branch moves") => {
        // fall back to direct (non-transaction) branch move API
        but_workspace::branch::move_adhoc(repo, &branch, &onto)?
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling stack_branch_on where the target branch is an ad-hoc single branch (not part of a managed workspace stack), producing a rebase outcome with new_tip or branch_stack_order as None.

Common situations: Automating branch moves on plain single branches outside workspace management; calling the transaction API for operations the non-transaction (direct) API supports; repos where the branch isn't assigned to a workspace/stack.

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/5ffede1d5ef864d7. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-transaction/src/lib.rs:506

    /// field is ever set rather than silently dropping a metadata reorder or a required checkout.
    ///
    /// [`Outcome::new_tip`]: but_workspace::branch::move_branch::Outcome::new_tip
    /// [`Outcome::branch_stack_order`]: but_workspace::branch::move_branch::Outcome::branch_stack_order
    pub fn stack_branch_on(
        &mut self,
        source_branch: &FullNameRef,
        target_branch: &FullNameRef,
    ) -> anyhow::Result<()> {
        let (ws_meta, new_tip, branch_stack_order) = self.rebase(|editor, _| {
            let outcome = but_workspace::branch::move_branch(editor, source_branch, target_branch)?;
            Ok((
                (outcome.ws_meta, outcome.new_tip, outcome.branch_stack_order),
                MaterializeWithoutCheckout::No,
                outcome.rebase,
            ))
        })?;

        anyhow::ensure!(
            new_tip.is_none() && branch_stack_order.is_none(),
            "Ad-hoc (single-branch) branch moves are not supported inside transactions"
        );

        self.record_workspace_metadata_update(ws_meta)?;

        Ok(())
    }

    pub fn tear_off_branch(&mut self, source_branch: &FullNameRef) -> anyhow::Result<()> {
        let ws_meta = self.rebase(|editor, _| {
            let outcome = but_workspace::branch::tear_off_branch(editor, source_branch, None)?;
            Ok((
                outcome.ws_meta,
                MaterializeWithoutCheckout::No,
                outcome.rebase,
            ))
        })?;

View on GitHub (pinned to 58e5313667)