{"record":{"id":"76b2d84b9168ef94","repo":"gitbutlerapp/gitbutler","slug":"merge-conflict-when-computing-workspace-tree","errorCode":null,"errorMessage":"merge conflict when computing workspace tree","messagePattern":"merge conflict when computing workspace tree","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-workspace/src/branch_trees.rs","lineNumber":179,"sourceCode":"        return Ok(*workspace.heads.first().expect(\"List is length 1\"));\n    }\n\n    let mut output = workspace.base;\n    let base = workspace.base;\n\n    let (merge_options, conflict_kind) = repo.merge_options_fail_fast()?;\n\n    for head in &workspace.heads {\n        let mut merge = repo.merge_trees(\n            base,\n            output,\n            *head,\n            repo.default_merge_labels(),\n            merge_options.clone(),\n        )?;\n\n        if merge.has_unresolved_conflicts(conflict_kind) {\n            anyhow::bail!(\"merge conflict when computing workspace tree\");\n        }\n        output = merge.tree.write()?.detach();\n    }\n\n    Ok(output)\n}\n\n#[cfg(test)]\nmod tests {\n    use gix::object::tree::EntryKind;\n\n    use super::*;\n\n    fn tree(repo: &gix::Repository, files: &[(&str, &str)]) -> Result<gix::ObjectId> {\n        let mut tree = repo.empty_tree().edit()?;\n        for (path, contents) in files {\n            tree.upsert(\n                *path,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-workspace/src/branch_trees.rs#L161-L197","documentation":"merge_workspace computes the workspace tree by merging branch heads into the workspace; after performing a merge it checks for unresolved conflicts of the relevant kind. If unresolved conflicts remain when computing the workspace tree, it bails because no single merged tree can be produced.","triggerScenarios":"update_uncommitted_changes_with_tree or move_tree_between_workspaces triggers a merge whose result has_unresolved_conflicts(conflict_kind) == true — i.e. overlapping changes between workspace head and the branch being merged.","commonSituations":"Two branches touched the same lines/paths; moving files between workspaces where the destination already has conflicting content; stale workspace state after a rebase or manual conflict edit; binary or rename/rename conflicts the merge driver cannot auto-resolve.","solutions":["Resolve the underlying git conflicts on the involved branches (checkout, merge manually, or use the UI conflict resolution) and retry","Inspect which files conflict (git status / gitbutler state) and normalize branch contents before the operation","Update/rebase the branch onto the current workspace head so the merge becomes trivial","If state is stale, discard/rebuild workspace state (but status refresh) so merges recompute from clean heads"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before the operation\nlet conflicts = repo.check_merge_conflicts(head_a, head_b)?;\nif conflicts { /* resolve or warn before calling merge-dependent APIs */ }","typeGuard":null,"tryCatchPattern":"match result {\n  Err(e) if e.to_string().contains(\"merge conflict when computing workspace tree\") => {\n    // enter conflict-resolution flow: list conflicting files, guide user\n  }\n  r => r?,\n}","preventionTips":["Keep branches rebased onto the workspace head","Resolve conflicts promptly instead of stacking operations","Avoid moving trees between workspaces with overlapping changes","Run a dry-run status/merge check first"],"tags":["git","merge","conflict","workspace"],"backgroundTag":"git-command-failed","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"}