Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions conventional_pre_commit/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ def has_autosquash_prefix(self, commit_msg: str = ""):

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


class ConventionalCommit(Commit):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,16 @@ def test_has_autosquash_prefix(commit, input, expected_result):
[
("Merge branch '2.x.x' into '1.x.x'", True),
("merge branch 'dev' into 'main'", True),
("Merge remote-tracking branch 'origin/master'", True),
("Merge pull request #123 from user/feature-branch", True),
("Merge tag 'v1.2.3' into main", True),
("Merge origin/master into develop", True),
("Merge refs/heads/main into develop", True),
("nope not a merge commit", False),
("type: subject", False),
("fix: merge bug in auth logic", False),
("chore: merged upstream changes", False),
("MergeSort implemented and tested", False),
],
)
def test_is_merge_commit(input, expected_result):
Expand Down
Loading