{"record":{"id":"06eae818c234e3df","repo":"gitbutlerapp/gitbutler","slug":"cannot-unapply-workspace-reference-by-checking-out","errorCode":null,"errorMessage":"Cannot unapply workspace reference by checking out conflicted commit at '{}'","messagePattern":"Cannot unapply workspace reference by checking out conflicted commit at '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":669,"sourceCode":"\n    /// Check out `ref_to_checkout` using the workspace traversal entrypoint as the\n    /// current worktree/index source.\n    ///\n    /// `ws` must be the workspace projection for the currently checked-out `HEAD`.\n    /// Its graph entrypoint is therefore the commit the index and worktree are\n    /// expected to match before checkout. This matters when `HEAD` points at a\n    /// stack segment inside the workspace rather than the workspace tip.\n    ///\n    /// The helper only updates the index/worktree according to `options`; callers\n    /// remain responsible for any subsequent `HEAD`, reference, metadata, and\n    /// projection updates.\n    fn safe_checkout_ref_to_checkout(\n        repo: &gix::Repository,\n        ref_to_checkout: &RefToCheckout,\n        options: but_core::worktree::checkout::Options,\n    ) -> anyhow::Result<but_core::worktree::checkout::Outcome> {\n        if but_core::Commit::from_id(ref_to_checkout.commit_id.attach(repo))?.is_conflicted() {\n            bail!(\n                \"Cannot unapply workspace reference by checking out conflicted commit at '{}'\",\n                ref_to_checkout.ref_name.shorten()\n            );\n        }\n        safe_checkout(repo, ref_to_checkout.commit_id, options)\n    }\n\n    /// Return the commit the workspace ref should point to when no workspace merge commit remains.\n    ///\n    /// A single remaining future tip is preferred. Otherwise, an empty workspace falls back to the\n    /// resolved target or the workspace lower bound.\n    fn commit_to_point_workspace_ref_to_after_unapply(\n        ws: &but_graph::Workspace,\n        future_workspace_tips: &[crate::commit::merge::Tip],\n    ) -> anyhow::Result<gix::ObjectId> {\n        if let Some(tip) = future_workspace_tips.first() {\n            return Ok(tip.commit_id);\n        }","sourceCodeStart":651,"sourceCodeEnd":687,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L651-L687","documentation":"Before checking out the reference that replaces an unapplied workspace, `safe_checkout_ref_to_checkout` verifies that the destination commit is not conflicted. A conflicted destination would leave the worktree in a broken state, so the unapply is rejected with this message naming the ref.","triggerScenarios":"`unapply` (or `unapply_workspace_reference`) computing a `RefToCheckout` whose `commit_id` satisfies `but_core::Commit::is_conflicted()`.","commonSituations":"Unapplying a workspace whose fallback checkout target (e.g. the remaining base branch) contains conflicted commits produced by earlier merges.","solutions":["Resolve and commit (or discard) the conflicted commits at the target reference first","Point the checkout at a clean ancestor commit or a different clean branch","Refresh/rebuild the workspace so a clean checkout target is chosen, then retry"],"exampleFix":"// before\nunapply(repo, meta, &ws, branch, opts)?;\n// after\nlet target = ref_to_checkout_after_workspace_unapply(&ws)?;\nif but_core::Commit::from_id(target.commit_id.attach(&repo))?.is_conflicted() {\n    anyhow::bail!(\"resolve conflicts at {} first\", target.ref_name.shorten());\n}\nunapply(repo, meta, &ws, branch, opts)?;","handlingStrategy":"validation","validationCode":"fn checkout_target_is_clean(repo: &gix::Repository, r: &RefToCheckout) -> bool {\n    but_core::Commit::from_id(r.commit_id.attach(repo))\n        .map(|c| !c.is_conflicted())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify destination refs point at non-conflicted commits before unapply","Complete conflict resolution workflows before dissolving workspaces"],"tags":["git","conflict","checkout","workspace"],"backgroundTag":"git-merge-conflict-unresolved","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"}