Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions gptdiff/applydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,30 @@ def dedup_diffs(diffs):
groups[key].append(value)
return [[key, "\n".join(values)] for key, values in groups.items()]

# Special case: handle LLM-style patch delimiters
if "*** Begin Patch" in diff_text:
lines = diff_text.splitlines()
diffs = []
current_lines = []
current_file = None
in_patch = False
for line in lines:
stripped = line.strip()
if stripped == "*** Begin Patch":
in_patch = True
current_lines = []
current_file = None
elif stripped == "*** End Patch":
if current_file is not None:
diffs.append((current_file, "\n".join(current_lines)))
in_patch = False
elif in_patch:
if stripped.startswith("*** Update File:"):
current_file = stripped.split(":", 1)[1].strip()
else:
current_lines.append(line)
return dedup_diffs(diffs)

header_re = re.compile(r'^(?:diff --git\s+)?(a/[^ ]+)\s+(b/[^ ]+)\s*$', re.MULTILINE)
lines = diff_text.splitlines()

Expand Down
14 changes: 14 additions & 0 deletions tests/test_parse_diff_per_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,19 @@ def test_parse_diff_per_file_unconventional_header():
assert "+++ game.js" in patch, "Expected patch to include '+++ game.js'"
assert "+let player" in patch, "Expected patch to include added lines"

def test_begin_patch_format():
diff_text = """*** Begin Patch
*** Update File: services/clerkReportPdf.tsx
@@
-changes1
+changes2
*** End Patch"""
result = parse_diff_per_file(diff_text)
assert len(result) == 1
file_path, patch = result[0]
assert file_path == "services/clerkReportPdf.tsx"
assert "-changes1" in patch
assert "+changes2" in patch

if __name__ == '__main__':
unittest.main()