{"record":{"id":"e2085d43fcbcddd7","repo":"GitoxideLabs/gitoxide","slug":"tree-conflicted-refusing-to-write-commit","errorCode":null,"errorMessage":"Tree conflicted, refusing to write commit","messagePattern":"Tree conflicted, refusing to write commit","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"gitoxide-core/src/repository/merge/tree.rs","lineNumber":90,"sourceCode":"                .into(),\n            current: ours_ref\n                .as_ref()\n                .map_or(ours_id_str.as_str().into(), |n| n.as_bstr())\n                .into(),\n            other: theirs_ref\n                .as_ref()\n                .map_or(theirs_id_str.as_str().into(), |n| n.as_bstr())\n                .into(),\n        };\n        let res = repo.merge_trees(base_id, ours_id, theirs_id, labels, options)?;\n        let has_conflicts = !res.conflicts.is_empty();\n        let has_unresolved_conflicts = res.has_unresolved_conflicts(TreatAsUnresolved::default());\n        if message.is_some() && has_unresolved_conflicts {\n            write_unresolved_conflict_paths(err, &res.conflicts)?;\n            if debug {\n                writeln!(err, \"{:#?}\", res.conflicts)?;\n            }\n            bail!(\"Tree conflicted, refusing to write commit\");\n        }\n\n        let tree_id = {\n            let _span = gix::trace::detail!(\"Writing merged tree\");\n            let mut written = 0;\n            let tree_id = res\n                .tree\n                .detach()\n                .write(|tree| {\n                    written += 1;\n                    repo.write(tree)\n                })\n                .map_err(|err| anyhow!(\"{err}\"))?;\n            writeln!(out, \"{tree_id} (wrote {written} trees)\")?;\n            tree_id\n        };\n\n        let conflicts = res.conflicts;","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gitoxide-core/src/repository/merge/tree.rs#L72-L108","documentation":"When a commit message was supplied (i.e. the merge is meant to produce a commit), the merge-tree operation refuses to write that commit if the merged tree still contains unresolved conflicts. Conflict paths are printed to stderr first so the caller can resolve them, then the command bails.","triggerScenarios":"Running `gix repo merge tree --message ...` where `res.has_unresolved_conflicts(TreatAsUnresolved::default())` returns true for the merge result.","commonSituations":"Merging branches with genuinely conflicting hunks; re-running an automated merge after a previous partial resolution; conflicts involving file/directory collisions or rename/rename cases the resolver leaves open.","solutions":["Inspect the conflict paths printed to stderr and resolve them (edit the tree, rerun with resolved inputs, or use `gix repo merge` with conflict resolution).","Run without `--message` to obtain the conflicted tree/ids without attempting a commit, resolve manually, then commit yourself.","Pick different base/ours/theirs revisions if the conflict stems from stale inputs."],"exampleFix":"// before (automated commit despite conflicts)\ngix repo merge tree --update-head --message \"merge\" <base> <ours> <theirs>\n// after (let conflicts surface, resolve, then commit)\ngix repo merge tree <base> <ours> <theirs>  # review conflicted paths\n# resolve, then:\ngix repo merge tree --update-head --message \"merge\" <base> <ours> <theirs>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match merge_tree(...) {\n    Err(e) if e.to_string().contains(\"Tree conflicted, refusing to write commit\") => {\n        // read conflict paths from stderr, resolve, retry\n    }\n    r => r?,\n}","preventionTips":["Pre-check mergeability (merge_base + a dry run without --message) before requesting a commit.","Parse the conflicted paths the command prints to stderr and resolve them programmatically.","Never auto-commit merge results in CI without first checking `has_unresolved_conflicts`."],"tags":["merge","conflict","git","gitoxide"],"backgroundTag":"git-command-failed","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}