{"record":{"id":"668d6005e363d87e","repo":"gitbutlerapp/gitbutler","slug":"visible-worktree-worktree-name-head-changed-shap","errorCode":null,"errorMessage":"Visible worktree {worktree_name} HEAD changed shape during the edit: expected {}, got {}","messagePattern":"Visible worktree (.+?) HEAD changed shape during the edit: expected (.+?), got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/graph_rebase/materialize.rs","lineNumber":144,"sourceCode":"    /// one, validated against the shape recorded at editor creation.\n    pub(super) fn linked_checkout_specs(&self) -> Result<Vec<LinkedCheckoutSpec>> {\n        let mut specs = Vec::new();\n        for checkout in &self.checkouts {\n            let Checkout::Worktree {\n                worktree_name,\n                selector,\n                ref_name: expected_ref,\n                initial_head,\n                merge_base_override,\n            } = checkout\n            else {\n                continue;\n            };\n            let (target, actual_ref) = self\n                .checkout_target(*selector)?\n                .with_context(|| format!(\"Visible worktree {worktree_name} HEAD was removed\"))?;\n            if actual_ref != *expected_ref {\n                bail!(\n                    \"Visible worktree {worktree_name} HEAD changed shape during the edit: \\\n                     expected {}, got {}\",\n                    expected_ref\n                        .as_ref()\n                        .map_or_else(|| \"detached\".into(), ToString::to_string),\n                    actual_ref\n                        .as_ref()\n                        .map_or_else(|| \"detached\".into(), ToString::to_string)\n                );\n            }\n            specs.push(LinkedCheckoutSpec {\n                name: worktree_name.clone(),\n                initial_head: *initial_head,\n                ref_name: expected_ref.clone(),\n                target,\n                merge_base_override: *merge_base_override,\n            });\n        }","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-rebase/src/graph_rebase/materialize.rs#L126-L162","documentation":"During materialization of a rebased graph, the head of a visible (non-primary) worktree is checked to still point at the reference recorded in the original graph. If the actual ref differs from the expected one, the operation bails because silently re-parenting or rewiring a worktree whose HEAD moved could corrupt the user's working state. The library refuses to guess which shape is correct.","triggerScenarios":"Calling Editor::materialize (via the materialize flow) when a worktree named in the graph has had its HEAD changed between capture of the graph (e.g. checkout_target snapshot) and materialization: expected_ref is None (detached) but actual_ref is a branch, or expected a branch name but got detached or a different branch.","commonSituations":"Another process (IDE, but CLI, git command) checked out a different branch or detached HEAD in the worktree while a graph rebase/materialize was in flight; long-running editor sessions where a user manually moves the worktree HEAD; stale worktree metadata after a concurrent operation.","solutions":["Re-run the operation so a fresh graph/worktree snapshot is captured before materializing","Check `git worktree list` and `git -C <worktree> rev-parse --symbolic-full-name HEAD` to see what changed and restore the expected ref","Retry with no other git/but processes touching the worktree concurrently","If the change was intentional, rebuild the editor history so the new HEAD is the expected reference"],"exampleFix":"// before: HEAD moved behind your back -> error\neditor.materialize()?;\n// after: verify and restore before materializing\nlet actual = repo.find_worktree(&name)?.head()?.kind;\nif actual != expected_ref { /* re-sync worktree HEAD to expected_ref */ }\neditor.materialize()?;","handlingStrategy":"validation","validationCode":"let actual = repo.find_worktree(name)?.head()?;\nlet actual_ref = actual.referenced_name().map(|r| r.to_owned());\nif actual_ref != expected_ref { /* re-sync or restart operation */ }","typeGuard":"fn matches_expected(actual: Option<&gix::refs::FullNameRef>, expected: &Option<gix::refs::FullName>) -> bool {\n    match (expected, actual) {\n        (None, None) => true,\n        (Some(e), Some(a)) => e.as_ref() == a,\n        _ => false,\n    }\n}","tryCatchPattern":null,"preventionTips":["Avoid concurrent git/but operations on the same worktree","Snapshot and re-validate worktree HEAD immediately before materialize","Re-create the editor after any manual checkout in a worktree"],"tags":["git","worktree","concurrency","rebase"],"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"}