{"record":{"id":"b7f4a31d2fe60678","repo":"gitbutlerapp/gitbutler","slug":"couldn-t-find-workspace-head","errorCode":null,"errorMessage":"Couldn't find workspace head.","messagePattern":"Couldn't find workspace head\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/move_branch.rs","lineNumber":100,"sourceCode":"            }\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            });\n        }\n\n        let Some(workspace_head) = workspace.tip_commit().map(|commit| commit.id) else {\n            bail!(\"Couldn't find workspace head.\")\n        };\n        let head_selector = editor\n            .select_commit(workspace_head)\n            .context(\"Failed to find the workspace head in the graph.\")?;\n\n        let Some(lower_bound_ref) = workspace\n            .lower_bound_segment_id\n            .map(|segment_id| &workspace.graph[segment_id])\n            .and_then(|segment| segment.ref_name())\n        else {\n            bail!(\"Tearing off a branch requires a workspace common base\");\n        };\n\n        let target_selector = editor\n            .select_reference(lower_bound_ref)\n            .context(\"Failed to find target reference in graph.\")?;\n\n        let DisconnectParameters {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/move_branch.rs#L82-L118","documentation":"tear_off_branch() detaches a branch from its workspace stack, which requires rebasing against the workspace head commit. When the workspace graph has no tip commit (e.g. an empty workspace or a workspace without a managed workspace commit), the function cannot establish a base for the rebase and bails with this message.","triggerScenarios":"Calling but_workspace::branch::tear_off_branch() on a workspace whose tip_commit() returns None - typically an empty workspace with no commits, or a workspace reference that points to nothing.","commonSituations":"Operating on a freshly initialized or emptied workspace stack where all commits were removed; tearing off a branch before any workspace commit exists; workspace ref resolving to an unborn/invalid commit.","solutions":["Ensure the workspace has at least one commit (a workspace head) before tearing off branches","Create a commit in the workspace so tip_commit() returns Some","Skip tear-off for empty workspaces and use a different branch-management API"],"exampleFix":"// before\nlet outcome = tear_off_branch(editor, ref_name);\n// after\nif workspace.tip_commit().is_none() {\n    anyhow::bail!(\"workspace has no head commit; cannot tear off branch\");\n}\nlet outcome = tear_off_branch(editor, ref_name);","handlingStrategy":"validation","validationCode":"if workspace.tip_commit().is_none() {\n    // skip tear-off; workspace has no head commit\n}","typeGuard":"let has_head = workspace.tip_commit().map(|c| c.id).is_some();","tryCatchPattern":"match tear_off_branch(editor, ref_name) {\n    Err(e) if e.to_string().contains(\"Couldn't find workspace head\") => handle_empty_workspace(),\n    other => other?,\n}","preventionTips":["Check tip_commit() before any stack-reordering operation","Never operate on workspaces with zero commits","Recreate the workspace commit after operations that empty the stack"],"tags":["git","workspace","precondition"],"backgroundTag":"resource-not-found","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"}