{"record":{"id":"f1796c4ce4a6cffc","repo":"gitbutlerapp/gitbutler","slug":"refusing-to-work-on-workspace-whose-workspace-comm-f1796c","errorCode":null,"errorMessage":"Refusing to work on workspace whose workspace commit isn't at the top","messagePattern":"Refusing to work on workspace whose workspace commit isn't at the top","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":205,"sourceCode":"    #[tracing::instrument(skip(workspace, repo, meta), err(Debug))]\n    pub fn unapply<'ws>(\n        branch: &FullNameRef,\n        workspace: &'ws but_graph::Workspace,\n        repo: &gix::Repository,\n        meta: &mut impl RefMetadata,\n        Options {\n            workspace_disposition,\n        }: Options,\n    ) -> anyhow::Result<Outcome<'ws>> {\n        let ws = workspace;\n        let mut branch_ref = try_find_validated_ref(repo, branch, \"unapply\")?;\n        let branch_commit_id = branch_ref\n            .as_mut()\n            .map(|reference| reference.peel_to_id().map(|id| id.detach()))\n            .transpose()?;\n\n        if ws.has_workspace_commit_in_ancestry(repo) {\n            bail!(\"Refusing to work on workspace whose workspace commit isn't at the top\");\n        }\n\n        let workspace_ref_name = ws.ref_name().map(ToOwned::to_owned);\n        if matches!(ws.kind, but_graph::workspace::WorkspaceKind::AdHoc)\n            && branch_ref\n                .as_ref()\n                .zip(workspace_ref_name.as_ref())\n                .is_some_and(|(to_unapply, workspace_ref_name)| {\n                    to_unapply.name() == workspace_ref_name.as_ref()\n                })\n        {\n            bail!(\n                \"Cannot unapply branch '{branch}' from an ad-hoc workspace because the workspace cannot be empty\",\n                branch = branch.shorten()\n            );\n        }\n\n        if let Some(workspace_ref_name) = workspace_ref_name.as_ref()","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L187-L223","documentation":"This error is thrown by `but_workspace::branch::unapply` when the workspace's workspace commit exists in the ancestry of HEAD but is not HEAD itself. Unapply requires the workspace commit to be the tip so it can rewrite history on top of it; a stale/buried workspace commit means the workspace state is out of date.","triggerScenarios":"Calling `unapply` after new commits were created on the branch without the workspace being rebuilt, or after external git operations (rebase, reset, cherry-pick) moved HEAD beyond the workspace commit.","commonSituations":"Running `git pull`/`git commit` directly in a GitButler-managed workspace then trying to unapply a branch from the UI/CLI; a stale workspace after a version upgrade; concurrent modification of the repo.","solutions":["Refresh the workspace first (apply/assign operation that recreates the workspace commit at HEAD), then retry unapply","Commit or discard any in-progress changes so the workspace commit can be regenerated at the top","If HEAD moved via plain git commands, re-run the workspace projection (`but status` / reopen the project in GitButler)"],"exampleFix":"// before\nbut_workspace::branch::unapply(repo, meta, &ws, branch, ...)?;\n// after\nif ws.has_workspace_commit_in_ancestry(repo) {\n    // rebuild workspace so its commit is at the tip\n    but_workspace::ui::rebuild_workspace(...)?;\n}\nbut_workspace::branch::unapply(repo, meta, &ws, branch, ...)?;","handlingStrategy":"validation","validationCode":"fn workspace_commit_is_tip(ws: &Workspace, repo: &gix::Repository) -> bool {\n    !ws.has_workspace_commit_in_ancestry(repo)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rebuild/refresh the workspace after any external git mutation before workspace operations","Avoid mixing plain git commands (commit/rebase/pull) with GitButler workspace operations on the same repo"],"tags":["git","workspace","state-conflict"],"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"}