better_patch: detect already-applied patches via reverse-check

Before attempting git apply, run git apply --check --reverse to see
if the patch is already present. If it is, return success immediately
instead of falling through to fuzzy apply and reporting FAILED.
This commit is contained in:
oxmc
2026-06-16 08:25:20 -07:00
parent fbc2d1e277
commit 7566763f89
+17 -1
View File
@@ -125,7 +125,23 @@ class GitPatchHandler:
if not self.use_git:
return self._fallback_patch_apply(str(patch_path), str(target_path))
# Check if patch is already applied before attempting to apply it
try:
check = subprocess.run(
['git', 'apply', '--check', '--reverse', '--ignore-space-change', str(patch_path)],
cwd=str(target_path), capture_output=True, text=True, timeout=30
)
if check.returncode == 0:
self._log('Patch already applied (reverse-check confirmed)')
return {
'success': True,
'message': 'Patch already applied',
'method': 'git'
}
except Exception:
pass # If reverse-check errors, fall through to normal apply
try:
# Use git apply with 3-way merge for better conflict resolution
cmd = [