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
14 changes: 10 additions & 4 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,21 @@ def main():

if args.version:
warnings.warn(
"'cz --version' will be deprecated in next major version. "
"Please use 'cz version' command from your scripts"
(
"'cz --version' will be deprecated in next major version. "
"Please use 'cz version' command from your scripts"
),
category=DeprecationWarning,
)
args.func = commands.Version

if args.debug:
warnings.warn(
"Debug will be deprecated in next major version. "
"Please remove it from your scripts"
(
"Debug will be deprecated in next major version. "
"Please remove it from your scripts"
),
category=DeprecationWarning,
)
logging.getLogger("commitizen").setLevel(logging.DEBUG)

Expand Down
7 changes: 6 additions & 1 deletion commitizen/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import re
import warnings
from typing import Dict, Optional

from commitizen import factory, git, out
from commitizen.config import BaseConfig
from commitizen.error_codes import INVALID_COMMIT_MSG
from commitizen.error_codes import INVALID_COMMIT_MSG, NO_COMMITS_FOUND


class Check:
Expand Down Expand Up @@ -50,6 +51,10 @@ def __call__(self):

"""
commit_msgs = self._get_commit_messages()
if not commit_msgs:
warnings.warn(f"No commit found with range: '{self.rev_range}'")
raise SystemExit(NO_COMMITS_FOUND)

pattern = self.cz.schema_pattern()
for commit_msg in commit_msgs:
if not Check.validate_commit_message(commit_msg, pattern):
Expand Down
8 changes: 8 additions & 0 deletions tests/commands/test_check_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,11 @@ def test_check_command_with_invalid_argment(args, config, capsys):
commands.Check(config=config, arguments=args)
_, err = capsys.readouterr()
assert "One and only one argument is required for check command!" in err


def test_check_command_with_empty_range(config, mocker, capsys):
check_cmd = commands.Check(config=config, arguments={"rev_range": "master..master"})
with pytest.raises(SystemExit), pytest.warns(UserWarning) as record:
check_cmd()

assert record[0].message.args[0] == "No commit found with range: 'master..master'"
27 changes: 23 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,29 @@ def test_ls(mocker, capsys):
assert isinstance(out, str)


def test_version(mocker, capsys):
def test_arg_version(mocker, capsys):
testargs = ["cz", "--version"]
mocker.patch.object(sys, "argv", testargs)

cli.main()
out, _ = capsys.readouterr()
assert out.strip() == __version__
with pytest.warns(DeprecationWarning) as record:
cli.main()
out, _ = capsys.readouterr()
assert out.strip() == __version__

assert record[0].message.args[0] == (
"'cz --version' will be deprecated in next major version. "
"Please use 'cz version' command from your scripts"
)


def test_arg_debug(mocker):
testargs = ["cz", "--debug", "info"]
mocker.patch.object(sys, "argv", testargs)

with pytest.warns(DeprecationWarning) as record:
cli.main()

assert record[0].message.args[0] == (
"Debug will be deprecated in next major version. "
"Please remove it from your scripts"
)