gitbutlerapp/gitbutler · error

Cannot unapply workspace reference by checking out…

Error message

Cannot unapply workspace reference by checking out conflicted commit at '{}'

What it means

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.

Solutions

  1. Resolve and commit (or discard) the conflicted commits at the target reference first
  2. Point the checkout at a clean ancestor commit or a different clean branch
  3. Refresh/rebuild the workspace so a clean checkout target is chosen, then retry

Example fix

// before
unapply(repo, meta, &ws, branch, opts)?;
// after
let target = ref_to_checkout_after_workspace_unapply(&ws)?;
if but_core::Commit::from_id(target.commit_id.attach(&repo))?.is_conflicted() {
    anyhow::bail!("resolve conflicts at {} first", target.ref_name.shorten());
}
unapply(repo, meta, &ws, branch, opts)?;
Defensive patterns

Strategy: validation

Validate before calling

fn checkout_target_is_clean(repo: &gix::Repository, r: &RefToCheckout) -> bool {
    but_core::Commit::from_id(r.commit_id.attach(repo))
        .map(|c| !c.is_conflicted())
        .unwrap_or(false)
}

Prevention

When it happens

Trigger: `unapply` (or `unapply_workspace_reference`) computing a `RefToCheckout` whose `commit_id` satisfies `but_core::Commit::is_conflicted()`.

Common situations: Unapplying a workspace whose fallback checkout target (e.g. the remaining base branch) contains conflicted commits produced by earlier merges.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/06eae818c234e3df. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/branch/unapply.rs:669

    /// Check out `ref_to_checkout` using the workspace traversal entrypoint as the
    /// current worktree/index source.
    ///
    /// `ws` must be the workspace projection for the currently checked-out `HEAD`.
    /// Its graph entrypoint is therefore the commit the index and worktree are
    /// expected to match before checkout. This matters when `HEAD` points at a
    /// stack segment inside the workspace rather than the workspace tip.
    ///
    /// The helper only updates the index/worktree according to `options`; callers
    /// remain responsible for any subsequent `HEAD`, reference, metadata, and
    /// projection updates.
    fn safe_checkout_ref_to_checkout(
        repo: &gix::Repository,
        ref_to_checkout: &RefToCheckout,
        options: but_core::worktree::checkout::Options,
    ) -> anyhow::Result<but_core::worktree::checkout::Outcome> {
        if but_core::Commit::from_id(ref_to_checkout.commit_id.attach(repo))?.is_conflicted() {
            bail!(
                "Cannot unapply workspace reference by checking out conflicted commit at '{}'",
                ref_to_checkout.ref_name.shorten()
            );
        }
        safe_checkout(repo, ref_to_checkout.commit_id, options)
    }

    /// Return the commit the workspace ref should point to when no workspace merge commit remains.
    ///
    /// A single remaining future tip is preferred. Otherwise, an empty workspace falls back to the
    /// resolved target or the workspace lower bound.
    fn commit_to_point_workspace_ref_to_after_unapply(
        ws: &but_graph::Workspace,
        future_workspace_tips: &[crate::commit::merge::Tip],
    ) -> anyhow::Result<gix::ObjectId> {
        if let Some(tip) = future_workspace_tips.first() {
            return Ok(tip.commit_id);
        }

View on GitHub (pinned to 58e5313667)