2 parents f9ba5db + 07af540 commit cb02c5bCopy full SHA for cb02c5b
2 files changed
pre_commit_hooks/check_merge_conflict.py
@@ -3,6 +3,8 @@
3
from typing import Optional
4
from typing import Sequence
5
6
+from pre_commit_hooks.util import cmd_output
7
+
8
9
CONFLICT_PATTERNS = [
10
b'<<<<<<< ',
@@ -12,13 +14,14 @@
12
14
]
13
15
16
-def is_in_merge() -> int:
17
+def is_in_merge() -> bool:
18
+ git_dir = cmd_output('git', 'rev-parse', '--git-dir').rstrip()
19
return (
- os.path.exists(os.path.join('.git', 'MERGE_MSG')) and
20
+ os.path.exists(os.path.join(git_dir, 'MERGE_MSG')) and
21
(
- os.path.exists(os.path.join('.git', 'MERGE_HEAD')) or
- os.path.exists(os.path.join('.git', 'rebase-apply')) or
- os.path.exists(os.path.join('.git', 'rebase-merge'))
22
+ os.path.exists(os.path.join(git_dir, 'MERGE_HEAD')) or
23
+ os.path.exists(os.path.join(git_dir, 'rebase-apply')) or
24
+ os.path.exists(os.path.join(git_dir, 'rebase-merge'))
25
)
26
27
tests/check_merge_conflict_test.py
@@ -135,3 +135,15 @@ def test_care_when_assumed_merge(tmpdir):
135
f = tmpdir.join('README.md')
136
f.write_binary(b'problem\n=======\n')
137
assert main([str(f.realpath()), '--assume-in-merge']) == 1
138
139
140
+def test_worktree_merge_conflicts(f1_is_a_conflict_file, tmpdir):
141
+ worktree = tmpdir.join('worktree')
142
+ cmd_output('git', 'worktree', 'add', str(worktree))
143
+ with worktree.as_cwd():
144
+ cmd_output(
145
+ 'git', 'pull', '--no-rebase', 'origin', 'master', retcode=None,
146
+ )
147
+ msg = f1_is_a_conflict_file.join('.git/worktrees/worktree/MERGE_MSG')
148
+ assert msg.exists()
149
+ test_merge_conflicts_git()
0 commit comments