{"record":{"id":"c4c67232b65ae4e2","repo":"gitbutlerapp/gitbutler","slug":"cannot-unapply-branch-by-checking-out-conflicted-c","errorCode":null,"errorMessage":"Cannot unapply branch by checking out conflicted commit {new_head_id}","messagePattern":"Cannot unapply branch by checking out conflicted commit (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":647,"sourceCode":"            if selected\n                .as_ref()\n                .is_none_or(|(best_generation, _)| generation < *best_generation)\n            {\n                selected = Some((generation, ref_to_checkout));\n            }\n        }\n        Ok(selected.map(|(_, ref_to_checkout)| ref_to_checkout))\n    }\n\n    /// Run `safe_checkout`, but provide better error messages if the commit to checkout\n    /// is conflicted.\n    fn safe_checkout(\n        repo: &gix::Repository,\n        new_head_id: gix::ObjectId,\n        options: but_core::worktree::checkout::Options,\n    ) -> anyhow::Result<but_core::worktree::checkout::Outcome> {\n        if but_core::Commit::from_id(new_head_id.attach(repo))?.is_conflicted() {\n            bail!(\"Cannot unapply branch by checking out conflicted commit {new_head_id}\");\n        }\n        but_core::worktree::safe_checkout_from_head(new_head_id, repo, options)\n    }\n\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,","sourceCodeStart":629,"sourceCodeEnd":665,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L629-L665","documentation":"`safe_checkout` inspects the target commit before checking it out and aborts if it is a conflicted commit (contains conflict markers/conflict state recorded by GitButler). Checking out such a commit would put the worktree into a broken conflicted state during unapply.","triggerScenarios":"Unapply's internal checkout step (`safe_checkout_ref_to_checkout` / `checkout_and_update_workspace_ref`) resolved to a commit id for which `but_core::Commit::is_conflicted()` is true.","commonSituations":"Unapplying a branch whose merge state produced conflicted commits; target ref pointing at a commit created mid-conflict-resolution.","solutions":["Resolve or discard the conflicted commit(s) first (complete conflict resolution and commit)","Choose a different, non-conflicted target to check out after unapply","Abort the unapply and let the user fix conflicts in the UI before retrying"],"exampleFix":"// before\nsafe_checkout(repo, new_head_id, options)?;\n// after\nif but_core::Commit::from_id(new_head_id.attach(repo))?.is_conflicted() {\n    anyhow::bail!(\"resolve conflicts before unapply\");\n}\nsafe_checkout(repo, new_head_id, options)?;","handlingStrategy":"validation","validationCode":"fn is_clean_target(repo: &gix::Repository, id: gix::ObjectId) -> bool {\n    !but_core::Commit::from_id(id.attach(repo)).map_or(true, |c| c.is_conflicted())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve conflicted commits before workspace restructuring operations","Surface conflict state to users before offering unapply actions"],"tags":["git","conflict","checkout"],"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"}