Skip to content

Commit b01a1de

Browse files
committed
rerere: Skip mismatched marker sizes like git-rerere does
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
1 parent 0595a93 commit b01a1de

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

gitrevise/merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def normalize_conflict(
375375
line = next(lines, None)
376376
if line is None:
377377
raise ConflictParseFailed("unexpected eof")
378-
if line.startswith(b"<<<<<<<"):
378+
if line.startswith(b"<<<<<<< "):
379379
# parse recursive conflicts, including their processed output in the current hunk
380380
conflict = normalize_conflict(lines, None)
381381
if cur_hunk is not None:
@@ -393,7 +393,7 @@ def normalize_conflict(
393393
raise ConflictParseFailed("unexpected ======= conflict marker")
394394
other_hunk = cur_hunk
395395
cur_hunk = b""
396-
elif line.startswith(b">>>>>>>"):
396+
elif line.startswith(b">>>>>>> "):
397397
# end of conflict. update hasher, and return a normalized conflict
398398
if cur_hunk is None or other_hunk is None:
399399
raise ConflictParseFailed("unexpected >>>>>>> conflict marker")
@@ -426,7 +426,7 @@ def normalize_conflicted_file(body: bytes) -> Tuple[bytes, str]:
426426
line = next(lines, None)
427427
if line is None:
428428
return (normalized, hasher.hexdigest())
429-
if line.startswith(b"<<<<<<<"):
429+
if line.startswith(b"<<<<<<< "):
430430
normalized += normalize_conflict(lines, hasher)
431431
else:
432432
normalized += line

tests/test_rerere.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_normalize_conflicted_file():
235235
c
236236
==========
237237
d
238-
>>>>>>>>>> longer conflict marker, to be trimmed
238+
>>>>>>>>>> longer conflict marker, to be ignored
239239
"""
240240
)
241241
) == (
@@ -249,14 +249,14 @@ def test_normalize_conflicted_file():
249249
250250
unrelated line
251251
252-
<<<<<<<
252+
<<<<<<<<<< HEAD
253253
c
254-
=======
254+
==========
255255
d
256-
>>>>>>>
256+
>>>>>>>>>> longer conflict marker, to be ignored
257257
"""
258258
),
259-
"3d7cdc2948951408412cc64f3816558407f77e18",
259+
"0630df854874fc5ffb92a197732cce0d8928e898",
260260
)
261261

262262
# Discard original-text-marker from merge.conflictStyle diff3.
@@ -314,18 +314,18 @@ def test_normalize_conflicted_file():
314314
normalize_conflicted_file(
315315
dedent(
316316
"""\
317-
<<<<<<<
317+
<<<<<<< ours (outer)
318318
outer left
319-
<<<<<<<<<<<
319+
<<<<<<< ours (inner)
320320
inner left
321-
|||||||||||
321+
|||||||
322322
inner diff3 original section
323-
===========
323+
=======
324324
inner right
325-
>>>>>>>>>>>
325+
>>>>>>> theirs (inner)
326326
=======
327327
outer right
328-
>>>>>>>
328+
>>>>>>> theirs (outer)
329329
"""
330330
)
331331
)[0]

0 commit comments

Comments
 (0)