{"record":{"id":"5ffede1d5ef864d7","repo":"gitbutlerapp/gitbutler","slug":"ad-hoc-single-branch-branch-moves-are-not-suppor","errorCode":null,"errorMessage":"Ad-hoc (single-branch) branch moves are not supported inside transactions","messagePattern":"Ad-hoc \\(single-branch\\) branch moves are not supported inside transactions","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-transaction/src/lib.rs","lineNumber":506,"sourceCode":"    /// field is ever set rather than silently dropping a metadata reorder or a required checkout.\n    ///\n    /// [`Outcome::new_tip`]: but_workspace::branch::move_branch::Outcome::new_tip\n    /// [`Outcome::branch_stack_order`]: but_workspace::branch::move_branch::Outcome::branch_stack_order\n    pub fn stack_branch_on(\n        &mut self,\n        source_branch: &FullNameRef,\n        target_branch: &FullNameRef,\n    ) -> anyhow::Result<()> {\n        let (ws_meta, new_tip, branch_stack_order) = self.rebase(|editor, _| {\n            let outcome = but_workspace::branch::move_branch(editor, source_branch, target_branch)?;\n            Ok((\n                (outcome.ws_meta, outcome.new_tip, outcome.branch_stack_order),\n                MaterializeWithoutCheckout::No,\n                outcome.rebase,\n            ))\n        })?;\n\n        anyhow::ensure!(\n            new_tip.is_none() && branch_stack_order.is_none(),\n            \"Ad-hoc (single-branch) branch moves are not supported inside transactions\"\n        );\n\n        self.record_workspace_metadata_update(ws_meta)?;\n\n        Ok(())\n    }\n\n    pub fn tear_off_branch(&mut self, source_branch: &FullNameRef) -> anyhow::Result<()> {\n        let ws_meta = self.rebase(|editor, _| {\n            let outcome = but_workspace::branch::tear_off_branch(editor, source_branch, None)?;\n            Ok((\n                outcome.ws_meta,\n                MaterializeWithoutCheckout::No,\n                outcome.rebase,\n            ))\n        })?;","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-transaction/src/lib.rs#L488-L524","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Perform the ad-hoc branch move outside a transaction using the direct branch-manipulation APIs in but-workspace/but-core","Ensure the branch belongs to a workspace stack so branch_stack_order is computed","Reassign or initialize the workspace for the branch before stacking operations inside the transaction","Restructure automation so stack moves happen via the stack API and single-branch moves via plain rebase"],"exampleFix":"// before\nlet mut tx = repo.transaction()?;\ntx.stack_branch_on(&adhoc_branch, &target)?; // errors for ad-hoc branch\n// after\nlet mut tx = repo.transaction()?;\ntx.stack_branch_on(&stacked_branch, &target)?; // branch must be in a stack\n// or for ad-hoc: but_workspace::branch::move_direct(...)\n","handlingStrategy":"validation","validationCode":"// only call stack_branch_on for branches managed in a workspace stack\nlet is_stacked = workspace.stacks.iter()\n    .any(|s| s.branches.iter().any(|b| b.ref_name == branch.ref_name));\nif !is_stacked { return Err(anyhow!(\"use non-transactional move for ad-hoc branch\")); }","typeGuard":null,"tryCatchPattern":"match tx.stack_branch_on(&branch, &onto) {\n    Err(e) if format!(\"{e:#}\").contains(\"Ad-hoc (single-branch) branch moves\") => {\n        // fall back to direct (non-transaction) branch move API\n        but_workspace::branch::move_adhoc(repo, &branch, &onto)?\n    }\n    r => r?,\n}","preventionTips":["Confirm branch membership in a workspace stack before transactional stack ops","Use plain rebase APIs for single-branch work","Document which operations are transaction-only vs direct"],"tags":["git","transaction","workspace","unsupported"],"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"}