Skip to content

Commit

Permalink
rerere: Skip mismatched marker sizes like git-rerere does
Browse files Browse the repository at this point in the history
git-rerere strictly ignores conflict markers that are not exactly the
expected length. For `<` and `>`, it also requires them to end in a
space.

See git/rerere.c:is_cmarker
  • Loading branch information
rwe committed Sep 29, 2021
1 parent 68cfb84 commit 3225bbb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions gitrevise/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def normalize_conflict(
line = next(lines, None)
if line is None:
raise ConflictParseFailed("unexpected eof")
if line.startswith(b"<<<<<<<"):
if line.startswith(b"<<<<<<< "):
# parse recursive conflicts, including their processed output in the current hunk
conflict = normalize_conflict(lines, None)
if cur_hunk is not None:
Expand All @@ -370,7 +370,7 @@ def normalize_conflict(
raise ConflictParseFailed("unexpected ======= conflict marker")
other_hunk = cur_hunk
cur_hunk = b""
elif line.startswith(b">>>>>>>"):
elif line.startswith(b">>>>>>> "):
# end of conflict. update hasher, and return a normalized conflict
if cur_hunk is None or other_hunk is None:
raise ConflictParseFailed("unexpected >>>>>>> conflict marker")
Expand Down Expand Up @@ -403,7 +403,7 @@ def normalize_conflicted_file(body: bytes) -> Tuple[bytes, str]:
line = next(lines, None)
if line is None:
return (normalized, hasher.hexdigest())
if line.startswith(b"<<<<<<<"):
if line.startswith(b"<<<<<<< "):
normalized += normalize_conflict(lines, hasher)
else:
normalized += line
22 changes: 11 additions & 11 deletions tests/test_rerere.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_normalize_conflicted_file():
c
==========
d
>>>>>>>>>> longer conflict marker, to be trimmed
>>>>>>>>>> longer conflict marker, to be ignored
"""
)
) == (
Expand All @@ -249,14 +249,14 @@ def test_normalize_conflicted_file():
unrelated line
<<<<<<<
<<<<<<<<<< HEAD
c
=======
==========
d
>>>>>>>
>>>>>>>>>> longer conflict marker, to be ignored
"""
),
"3d7cdc2948951408412cc64f3816558407f77e18",
"0630df854874fc5ffb92a197732cce0d8928e898",
)

# Discard original-text-marker from merge.conflictStyle diff3.
Expand Down Expand Up @@ -314,18 +314,18 @@ def test_normalize_conflicted_file():
normalize_conflicted_file(
dedent(
"""\
<<<<<<<
<<<<<<< ours (outer)
outer left
<<<<<<<<<<<
<<<<<<< ours (inner)
inner left
|||||||||||
|||||||
inner diff3 original section
===========
=======
inner right
>>>>>>>>>>>
>>>>>>> theirs (inner)
=======
outer right
>>>>>>>
>>>>>>> theirs (outer)
"""
)
)[0]
Expand Down

0 comments on commit 3225bbb

Please sign in to comment.