{"record":{"id":"ed7bd745c2b75f03","repo":"gitbutlerapp/gitbutler","slug":"visible-worktree-changed-since-the-editor-was-c","errorCode":null,"errorMessage":"Visible worktree {} changed since the editor was created: expected {} at {}, got {} at {}","messagePattern":"Visible worktree (.+?) changed since the editor was created: expected (.+?) at (.+?), got (.+?) at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-rebase/src/graph_rebase/materialize.rs","lineNumber":90,"sourceCode":"    repo: &gix::Repository,\n    specs: Vec<LinkedCheckoutSpec>,\n) -> Result<Vec<LinkedCheckoutRepo>> {\n    if specs.is_empty() {\n        return Ok(Vec::new());\n    }\n    let proxies = repo.worktrees()?;\n    specs\n        .into_iter()\n        .map(|spec| {\n            let proxy = proxies\n                .iter()\n                .find(|proxy| proxy.id() == spec.name.as_bstr())\n                .with_context(|| format!(\"Visible worktree {} no longer exists\", spec.name))?;\n            let worktree_repo = proxy.clone().into_repo()?;\n            let actual_ref = worktree_repo.head_name()?;\n            let actual_head = worktree_repo.head_id()?.detach();\n            if actual_ref != spec.ref_name || actual_head != spec.initial_head {\n                bail!(\n                    \"Visible worktree {} changed since the editor was created: \\\n                     expected {} at {}, got {} at {}\",\n                    spec.name,\n                    spec.ref_name\n                        .as_ref()\n                        .map_or_else(|| \"detached\".into(), ToString::to_string),\n                    spec.initial_head,\n                    actual_ref\n                        .as_ref()\n                        .map_or_else(|| \"detached\".into(), ToString::to_string),\n                    actual_head\n                );\n            }\n            Ok(LinkedCheckoutRepo {\n                repo: worktree_repo,\n                target: spec.target,\n                merge_base_override: spec.merge_base_override,\n            })","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-rebase/src/graph_rebase/materialize.rs#L72-L108","documentation":"Before materializing a rebase plan, the library re-opens each visible worktree and verifies its checked-out ref and HEAD still match what was recorded when the editor was created. If either changed, applying the plan could clobber concurrent work, so it aborts with expected vs actual ref and commit ids.","triggerScenarios":"Calling `materialize` (which runs `open_linked_checkout_repos`) after the editor was created, but in the meantime a worktree had its HEAD moved — e.g. a branch was checked out, reset, force-pushed, or the worktree went detached.","commonSituations":"Another terminal or IDE ran git checkout/reset in a worktree while the rebase editor was open; a background fetch updated a branch; long-running operations with slow user interaction allowing the repo state to drift.","solutions":["Recreate the editor from the current workspace state and re-apply the intended changes","Inspect the reported expected/actual ref and commit, then restore the worktree to the expected state (git checkout <ref>; git reset --hard <id>) if safe","Avoid mutating worktrees while a graph rebase editor is alive; perform mutations, then create the editor","Re-run materialize immediately after editor creation to minimize the race window"],"exampleFix":"// before: editor created, worktree mutated elsewhere, then\nmaterialize(editor, plan)?;\n// after: re-validate / recreate\nmatch materialize(editor, plan) {\n    Ok(r) => r,\n    Err(_) => {\n        let editor = create_with_opts(&fresh_workspace, &tips, opts)?;\n        materialize(editor, plan)?\n    }\n}","handlingStrategy":"try-catch","validationCode":"for spec in &editor.visible_checkouts() {\n    let repo = gix::open(worktree_path(&repo, &spec.name))?;\n    anyhow::ensure!(\n        repo.head_name().ok().as_ref() == Some(&spec.ref_name)\n            && repo.head_id().ok().map(|i| i.detach()) == Some(spec.initial_head),\n        \"worktree {} drifted since editor creation\", spec.name\n    );\n}","typeGuard":null,"tryCatchPattern":"match materialize(&repo, editor, plan) {\n    Ok(r) => r,\n    Err(e) if e.to_string().contains(\"changed since the editor was created\") => {\n        eprintln!(\"worktree moved; recreating editor from current state\");\n        let ws = but_workspace::refresh(&repo)?;\n        let editor = create_with_opts(&ws, &tips, opts)?;\n        materialize(&repo, editor, plan)?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Don't run git checkout/reset in worktrees while a rebase editor is open","Materialize promptly after creating the editor","Recreate the editor after any external git mutation"],"tags":["git","worktree","concurrency","stale-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"}