{"record":{"id":"176883324a12c632","repo":"gitbutlerapp/gitbutler","slug":"moving-branches-currently-need-a-workspace-commit","errorCode":null,"errorMessage":"Moving branches currently need a workspace commit","messagePattern":"Moving branches currently need a workspace commit","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/move_branch.rs","lineNumber":78,"sourceCode":"        subject_branch_name: &FullNameRef,\n        stack_id_override: Option<StackId>,\n    ) -> anyhow::Result<Outcome<'ws, 'meta, M>> {\n        let successful_rebase = editor.rebase()?;\n        let workspace = successful_rebase.overlayed_graph()?.into_workspace()?;\n        let mut editor = successful_rebase.into_editor();\n        let Some(source) = workspace.find_segment_and_stack_by_refname(subject_branch_name) else {\n            bail!(\n                \"Couldn't find branch to move in workspace with reference name: {subject_branch_name}\"\n            );\n        };\n\n        // We're currently stopping the move branch operations imperatively at this stage, in order to\n        // reduce the scope of this first iteration of moving the branches.\n        // TODO: Enable and test that we can move branches in any kind of workspace.\n        match &workspace.kind {\n            WorkspaceKind::Managed { .. } => {}\n            WorkspaceKind::ManagedMissingWorkspaceCommit { .. } => {\n                bail!(\"Moving branches currently need a workspace commit\")\n            }\n            WorkspaceKind::AdHoc => {\n                bail!(\"Moving branches in non-managed workspaces is not supported\");\n            }\n        };\n\n        let mut ws_meta = workspace.metadata.clone();\n\n        let (source_stack, subject_segment) = source;\n\n        if source_stack.segments.len() == 1 {\n            // There's only one branch in the source stack. Nothing to do.\n            return Ok(Outcome {\n                rebase: editor.rebase()?,\n                ws_meta,\n                new_tip: None,\n                branch_stack_order: None,\n            });","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/move_branch.rs#L60-L96","documentation":"Branch moving currently requires a workspace with an actual workspace commit. A ManagedMissingWorkspaceCommit workspace (managed but missing its workspace commit) is rejected because the rebase/overlay machinery underpinning the move has no commit to build on. The code marks this limitation with a TODO.","triggerScenarios":"Calling tear_off_branch against a workspace whose WorkspaceKind is ManagedMissingWorkspaceCommit — e.g. after the workspace commit was deleted, reset away, or a stack was emptied.","commonSituations":"Workspaces whose last commit was removed by external git commands (`git reset --hard` on the workspace branch, history rewriting tools), or freshly initialized managed workspaces that haven't committed yet.","solutions":["Restore or recreate the workspace commit (commit pending workspace changes) before moving branches","Recreate the workspace/stack via the library's normal creation flow so a workspace commit exists","Move the branch with plain git operations if the workspace is broken","awaiting library support for commit-less workspaces"],"exampleFix":"// before\nmove_branch.tear_off_branch(...)?; // workspace missing its commit\n// after\nworkspace.commit_missing_workspace_commit()?; // ensure a workspace commit exists\nteardown = move_branch.tear_off_branch(...);","handlingStrategy":"validation","validationCode":"fn movable_workspace(workspace: &Workspace) -> bool {\n    matches!(workspace.kind, WorkspaceKind::Managed { .. })\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"need a workspace commit\") => {\n        eprintln!(\"recreate the workspace commit before moving branches\");\n        anyhow::bail!(e);\n    }\n    other => other,\n}","preventionTips":["Avoid resetting/rewriting the workspace branch with raw git commands","Commit or restore workspace state before branch operations","Check WorkspaceKind before invoking move operations"],"tags":["git","workspace","unsupported-state"],"backgroundTag":"invalid-state-transition","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"}