Skip to content

Commit

Permalink
fix: compatible with unified diff
Browse files Browse the repository at this point in the history
Signed-off-by: thefool0 <74161809+thefool0000@users.noreply.github.com>
  • Loading branch information
thefool0000 authored and jingfelix committed Dec 22, 2024
1 parent 684c73a commit dfabc0e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Patche/utils/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Patche.model import Change, Diff, Hunk, Patch

git_diffcmd_header = re.compile("^diff --git a/(.+) b/(.+)$")
unified_diff_header = re.compile("^---\s{1}")
spliter_line = re.compile("^---$")


Expand Down Expand Up @@ -105,9 +106,14 @@ def parse_patch(text: str) -> Patch:
idx = 0
for i, line in enumerate(lines):
# 这里考虑 git log 格式和 git format-patch 格式
if git_diffcmd_header.match(line) or spliter_line.match(line):
if (
git_diffcmd_header.match(line)
or spliter_line.match(line)
or unified_diff_header.match(line)
):
idx = i
break

else:
# raise ValueError(
# "No diff --git line found, check if the input is a valid patch"
Expand Down

0 comments on commit dfabc0e

Please sign in to comment.