Skip to content

Commit a78f243

Browse files
committed
fix(commands/check): Show warning if no commit to check when running cz check --rev-range
#165
1 parent fc2ca69 commit a78f243

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎commitizen/commands/check.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
22
import re
3+
import warnings
34
from typing import Dict, Optional
45

56
from commitizen import factory, git, out
67
from commitizen.config import BaseConfig
7-
from commitizen.error_codes import INVALID_COMMIT_MSG
8+
from commitizen.error_codes import INVALID_COMMIT_MSG, NO_COMMITS_FOUND
89

910

1011
class Check:
@@ -50,6 +51,10 @@ def __call__(self):
5051
5152
"""
5253
commit_msgs = self._get_commit_messages()
54+
if not commit_msgs:
55+
warnings.warn(f"No commit found with range: '{self.rev_range}'")
56+
raise SystemExit(NO_COMMITS_FOUND)
57+
5358
pattern = self.cz.schema_pattern()
5459
for commit_msg in commit_msgs:
5560
if not Check.validate_commit_message(commit_msg, pattern):

‎tests/commands/test_check_command.py

+8
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,11 @@ def test_check_command_with_invalid_argment(args, config, capsys):
194194
commands.Check(config=config, arguments=args)
195195
_, err = capsys.readouterr()
196196
assert "One and only one argument is required for check command!" in err
197+
198+
199+
def test_check_command_with_empty_range(config, mocker, capsys):
200+
check_cmd = commands.Check(config=config, arguments={"rev_range": "master..master"})
201+
with pytest.raises(SystemExit), pytest.warns(UserWarning) as record:
202+
check_cmd()
203+
204+
assert record[0].message.args[0] == "No commit found with range: 'master..master'"

0 commit comments

Comments
 (0)