{"record":{"id":"7a7eb6731553c0fe","repo":"affaan-m/ECC","slug":"git-merge-tree-failed-stderr","errorCode":null,"errorMessage":"git merge-tree failed: {stderr}","messagePattern":"git merge-tree failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":808,"sourceCode":"        let overflow = conflicts.len().saturating_sub(3);\n        let detail = if overflow > 0 {\n            format!(\"{conflict_summary}, +{overflow} more\")\n        } else {\n            conflict_summary\n        };\n\n        return Ok(MergeReadiness {\n            status: MergeReadinessStatus::Conflicted,\n            summary: format!(\n                \"Merge blocked between {left_branch} and {right_branch} by {} conflict(s): {detail}\",\n                conflicts.len()\n            ),\n            conflicts,\n        });\n    }\n\n    let stderr = String::from_utf8_lossy(&output.stderr);\n    anyhow::bail!(\"git merge-tree failed: {stderr}\");\n}\n\npub fn branch_conflict_preview(\n    left: &WorktreeInfo,\n    right: &WorktreeInfo,\n    max_lines: usize,\n) -> Result<Option<BranchConflictPreview>> {\n    if left.base_branch != right.base_branch {\n        return Ok(None);\n    }\n\n    let repo_root = base_checkout_path(left)?;\n    let readiness = merge_readiness_for_branches(&repo_root, &left.branch, &right.branch)?;\n    if readiness.status != MergeReadinessStatus::Conflicted {\n        return Ok(None);\n    }\n\n    Ok(Some(BranchConflictPreview {","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L790-L826","documentation":"merge_readiness_for_branches runs `git merge-tree` to test whether merging the branch into its base would conflict. When the merge-tree invocation exits nonzero (not just 'has conflicts' output, but an actual git failure), the library bails with git's stderr.","triggerScenarios":"Calling merge_readiness / branch_conflict_preview on worktrees whose base or head ref is missing (unborn branch, deleted commit), a corrupt object database, or a git version too old to support the used merge-tree mode.","commonSituations":"Branch deleted on remote but still referenced locally; shallow clone missing objects; git < 2.38 lacking `--write-tree` merge-tree; repository corrupted after interrupted gc.","solutions":["Read the stderr — it names the missing ref or git-level failure.","`git fetch --all` to restore missing objects/refs in shallow or pruned clones.","Verify both refs resolve: `git rev-parse <base> <head>`.","Upgrade git to >= 2.38 if merge-tree --write-tree is unsupported.","Run `git fsck` if the object database looks corrupted."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn refs_resolve(path: &Path, refs: &[&str]) -> bool {\n    refs.iter().all(|r| Command::new(\"git\").arg(path).args([\"rev-parse\", \"--verify\", r])\n        .output().map(|o| o.status.success()).unwrap_or(false))\n}","typeGuard":null,"tryCatchPattern":"match merge_readiness(&wt) {\n    Ok(r) => use(r),\n    Err(e) => { log::error!(\"merge-tree failed: {e:#}\"); /* fall back to attempting the merge or surfacing the git error */ }\n}","preventionTips":["Fetch regularly so refs and objects are present","Avoid shallow clones for merge analysis","Require git >= 2.38 for merge-tree --write-tree","Run git fsck after suspicious interruptions"],"tags":["git","merge","conflict"],"backgroundTag":"git-command-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}