fix(agent): handled already-applied patch merges

Use git apply --3way for patch-mode isolated merge checks and applies so diff-tree patches that are already present are accepted as no-ops.

Added regression coverage for a clean already-applied binary/full-index patch.

Fixes #4135
This commit is contained in:
roboomp
2026-07-01 11:58:52 +00:00
parent f70e4f1570
commit 66052863bb
2 changed files with 51 additions and 3 deletions
@@ -291,11 +291,11 @@ export async function mergeIsolatedChanges(opts: IsolationMergeOptions): Promise
hadAnyChanges = false;
} else {
const normalized = patchText.endsWith("\n") ? patchText : `${patchText}\n`;
changesApplied = await git.patch.canApplyText(repoRoot, normalized);
changesApplied = await git.patch.canApplyText(repoRoot, normalized, { threeWay: true });
hadAnyChanges = false;
if (changesApplied) {
try {
await git.patch.applyText(repoRoot, normalized);
await git.patch.applyText(repoRoot, normalized, { threeWay: true });
hadAnyChanges = true;
} catch {
changesApplied = false;