Skip to content

Commit fa1915d

Browse files
authored
fix: skip merge commits patterns (#134)
2 parents 33500e9 + 347f0ed commit fa1915d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

conventional_pre_commit/format.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ def has_autosquash_prefix(self, commit_msg: str = ""):
7070

7171
def is_merge(self, commit_msg: str = ""):
7272
"""
73-
Returns True if input starts with "Merge branch"
74-
See the documentation, please https://git-scm.com/docs/git-merge.
73+
Returns True if the commit message indicates a merge commit.
74+
Matches messages that start with "Merge", including:
75+
- Merge branch ...
76+
- Merge pull request ...
77+
- Merge remote-tracking branch ...
78+
- Merge tag ...
79+
See https://git-scm.com/docs/git-merge.
7580
"""
7681
commit_msg = self.clean(commit_msg)
77-
return commit_msg.lower().startswith("merge branch ")
82+
return bool(re.match(r"^merge\b", commit_msg.lower()))
7883

7984

8085
class ConventionalCommit(Commit):

tests/test_format.py

+8
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,16 @@ def test_has_autosquash_prefix(commit, input, expected_result):
397397
[
398398
("Merge branch '2.x.x' into '1.x.x'", True),
399399
("merge branch 'dev' into 'main'", True),
400+
("Merge remote-tracking branch 'origin/master'", True),
401+
("Merge pull request #123 from user/feature-branch", True),
402+
("Merge tag 'v1.2.3' into main", True),
403+
("Merge origin/master into develop", True),
404+
("Merge refs/heads/main into develop", True),
400405
("nope not a merge commit", False),
401406
("type: subject", False),
407+
("fix: merge bug in auth logic", False),
408+
("chore: merged upstream changes", False),
409+
("MergeSort implemented and tested", False),
402410
],
403411
)
404412
def test_is_merge_commit(input, expected_result):

0 commit comments

Comments
 (0)