{"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":"anyhow::Error","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/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-workspace/src/branch/move_branch.rs#L82-L118","documentation":"`tear_off_branch` needs the workspace tip commit to anchor the graph rewrite (`editor.select_commit(workspace_head)`); if `workspace.tip_commit()` returns None it bails with this message. It occurs after the single-segment early-return, so the workspace has multiple segments but no resolvable tip.","triggerScenarios":"A multi-segment workspace whose tip commit cannot be resolved — workspace ref points at a missing/unreadable commit object (pruned, shallow/incomplete clone, corrupted odb), or the graph's tip metadata is absent after an interrupted update.","commonSituations":"Partial/shallow clones missing workspace objects; `git gc --prune` removing the workspace commit; interrupted workspace writes leaving refs pointing at absent objects.","solutions":["Fetch/repair the missing objects (`git fetch --unshallow` or restore from a remote/pack) and rebuild the workspace graph, then retry.","If the workspace tip is genuinely lost, re-establish the workspace (repair flow / re-create workspace commit) before moving branches.","Pre-check `workspace.tip_commit().is_some()` and block the move action with a clearer recovery message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if workspace.tip_commit().is_none() {\n    anyhow::bail!(\"workspace has no resolvable tip commit; fetch/repair missing objects before moving branches\");\n}","typeGuard":"fn workspace_has_resolvable_tip(ws: &but_graph::Workspace) -> bool {\n    ws.tip_commit().is_some()\n}","tryCatchPattern":"if let Err(err) = move_branch::tear_off_branch(editor, &branch, None) {\n    if err.to_string().contains(\"workspace head\") {\n        // workspace tip object missing: repair objects (fetch/unshallow) and rebuild the graph\n    }\n}","preventionTips":["In shallow/partial clones, ensure workspace objects are fetched before graph operations.","Pre-check workspace.tip_commit() and block stack mutations when it is None.","Avoid pruning workspace refs/objects with aggressive git gc settings."],"tags":["rust","git","but-workspace","move-branch","workspace-state","missing-commit"],"backgroundTag":"workspace-state-precondition","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}