From 7566763f899bd6b85b6cac8397df42b9b274f020 Mon Sep 17 00:00:00 2001 From: oxmc <67136658+oxmc@users.noreply.github.com> Date: Tue, 16 Jun 2026 08:25:20 -0700 Subject: [PATCH] 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. --- scripts/better_patch.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/better_patch.py b/scripts/better_patch.py index d99ab12..e754fa1 100644 --- a/scripts/better_patch.py +++ b/scripts/better_patch.py @@ -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 = [