Skip to content

Commit 6076fd1

Browse files
committed
Support rebase conflicts in check-merge-conflicts
1 parent 78818b9 commit 6076fd1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pre_commit_hooks/check_merge_conflict.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
def is_in_merge():
1616
return (
1717
os.path.exists(os.path.join('.git', 'MERGE_MSG')) and
18-
os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
18+
(
19+
os.path.exists(os.path.join('.git', 'MERGE_HEAD')) or
20+
os.path.exists(os.path.join('.git', 'rebase-apply')) or
21+
os.path.exists(os.path.join('.git', 'rebase-merge'))
22+
)
1923
)
2024

2125

tests/check_merge_conflict_test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def f1_is_a_conflict_file(tmpdir):
5454
'=======\n'
5555
'parent\n'
5656
'>>>>>>>'
57+
) or f1.startswith(
58+
# .gitconfig with [pull] rebase = preserve causes a rebase which
59+
# flips parent / child
60+
'<<<<<<< HEAD\n'
61+
'parent\n'
62+
'=======\n'
63+
'child\n'
64+
'>>>>>>>'
5765
)
5866
assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
5967
yield
@@ -85,7 +93,7 @@ def repository_is_pending_merge(tmpdir):
8593
repo2_f2.write('child\n')
8694
cmd_output('git', 'add', '--', repo2_f2.strpath)
8795
cmd_output('git', 'commit', '--no-gpg-sign', '-m', 'clone commit2')
88-
cmd_output('git', 'pull', '--no-commit')
96+
cmd_output('git', 'pull', '--no-commit', '--no-rebase')
8997
# We should end up in a pending merge
9098
assert repo2_f1.read() == 'parent\n'
9199
assert repo2_f2.read() == 'child\n'

0 commit comments

Comments
 (0)