{"record":{"id":"72ce8a35c0c5fa82","repo":"affaan-m/ECC","slug":"git-merge-failed-stderr","errorCode":null,"errorMessage":"git merge failed: {stderr}","messagePattern":"git merge failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":897,"sourceCode":"    }\n\n    if !git_status_short(&repo_root)?.is_empty() {\n        anyhow::bail!(\n            \"Repository root {} has uncommitted changes; commit or stash them before merging\",\n            repo_root.display()\n        );\n    }\n\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(&repo_root)\n        .args([\"merge\", \"--no-edit\", &worktree.branch])\n        .output()\n        .context(\"Failed to merge worktree branch into base\")?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git merge failed: {stderr}\");\n    }\n\n    let merged_output = format!(\n        \"{}\\n{}\",\n        String::from_utf8_lossy(&output.stdout),\n        String::from_utf8_lossy(&output.stderr)\n    );\n\n    Ok(MergeOutcome {\n        branch: worktree.branch.clone(),\n        base_branch: worktree.base_branch.clone(),\n        already_up_to_date: merged_output.contains(\"Already up to date.\"),\n    })\n}\n\npub fn rebase_onto_base(worktree: &WorktreeInfo) -> Result<RebaseOutcome> {\n    if has_uncommitted_changes(worktree)? {\n        anyhow::bail!(","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L879-L915","documentation":"This error is raised by `merge_into_base` when a `git merge --no-edit <branch>` command executed in the base checkout exits with a non-zero status. The library surfaces git's raw stderr so the developer can see the actual merge conflict or failure. It wraps all git-level merge failures, including conflicts, unrelated histories, and corrupt refs.","triggerScenarios":"Calling merge_into_base when the worktree branch and base branch have diverged and git cannot auto-merge (conflict markers required), when the merge is refused (e.g. 'refusing to merge unrelated histories'), or when the underlying git process fails for any reason.","commonSituations":"Parallel development where base branch advanced with conflicting edits; a worktree branch that was rebased onto a different root; a branch deleted or corrupted underneath the tool; divergent commits touching the same lines in the base checkout.","solutions":["Inspect the stderr in the message, run 'git merge --no-edit <branch>' manually in the base checkout to see conflict markers","Resolve conflicts: run 'git status', edit conflicted files, 'git add' them, 'git commit' to complete the merge","If conflicts are hard to reconcile, rebase the worktree branch onto the base first ('git rebase <base>') then retry","If histories are unrelated, merge with '--allow-unrelated-histories' or rebuild the branch from the correct base","Ensure the base checkout is clean and on the expected base branch before retrying"],"exampleFix":"// before (raw merge that fails)\nlet output = Command::new(\"git\").args([\"merge\", \"--no-edit\", &worktree.branch]).output()?;\n// after (pre-check the merge and abort cleanly on conflict)\nlet check = Command::new(\"git\").args([\"merge-tree\", \"--write-tree\", &worktree.branch]).output()?;\nanyhow::ensure!(check.status.success(), \"merge conflicts detected; resolve before merging\");","handlingStrategy":"try-catch","validationCode":"let check = Command::new(\"git\")\n    .args([\"merge-tree\", \"--write-tree\", &worktree.branch])\n    .current_dir(&repo_root)\n    .output()?;\nlet merge_clean = check.status.success();","typeGuard":"fn is_merge_conflict(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"CONFLICT\")\n}","tryCatchPattern":"match merge_into_base(&wt) {\n    Ok(outcome) => outcome,\n    Err(e) if e.to_string().contains(\"CONFLICT\") => {\n        eprintln!(\"Resolve merge conflicts in {} then retry\", wt.branch);\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep feature branches short-lived and merge back to base frequently","Rebase onto base regularly to surface conflicts early","Ensure the base checkout is clean and on the correct branch before merging","Dry-run with 'git merge-tree' or 'git merge --no-commit --no-ff' in scripts"],"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"}