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 = [