Skip to content

Commit

Permalink
fix(bump): raise non zero error code when there's no elegible commit …
Browse files Browse the repository at this point in the history
…to bump
  • Loading branch information
woile committed Jan 16, 2022
1 parent 323c72e commit dac6de0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ def __call__(self): # noqa: C901
out.write(information)

if increment is None and new_tag_version == current_tag_version:
raise NoneIncrementExit()
raise NoneIncrementExit(
"[NO_COMMITS_TO_BUMP]\n"
"The commits found are not elegible to be bumped"
)

# Do not perform operations over files or git.
if dry_run:
Expand Down
4 changes: 2 additions & 2 deletions commitizen/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class DryRunExit(ExpectedExit):
pass


class NoneIncrementExit(ExpectedExit):
pass
class NoneIncrementExit(CommitizenException):
exit_code = ExitCode.NO_COMMITS_FOUND


class NoCommitizenFoundException(CommitizenException):
Expand Down
16 changes: 12 additions & 4 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from commitizen import cli, cmd, git
from commitizen.exceptions import (
BumpTagFailedError,
CommitizenException,
CurrentVersionNotFoundError,
DryRunExit,
ExitCode,
ExpectedExit,
NoCommitsFoundError,
NoneIncrementExit,
Expand Down Expand Up @@ -327,7 +329,7 @@ def test_none_increment_exit_should_be_a_class():


def test_none_increment_exit_should_be_expected_exit_subclass():
assert issubclass(NoneIncrementExit, ExpectedExit)
assert issubclass(NoneIncrementExit, CommitizenException)


def test_none_increment_exit_should_exist_in_bump():
Expand All @@ -339,7 +341,9 @@ def test_none_increment_exit_is_exception():


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):
def test_none_increment_should_not_call_git_tag_and_error_code_is_not_zero(
mocker, tmp_commitizen_project
):
create_file_and_commit("test(test_get_all_droplets): fix bad comparison test")
testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)
Expand All @@ -350,8 +354,12 @@ def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):
git.tag = MagicMock(return_value=dummy_value)

with pytest.raises(NoneIncrementExit):
cli.main()
git.tag.assert_not_called()
try:
cli.main()
except NoneIncrementExit as e:
git.tag.assert_not_called()
assert e.exit_code == ExitCode.NO_COMMITS_FOUND
raise e

# restore pop stashed
git.tag = stashed_git_tag
Expand Down

0 comments on commit dac6de0

Please sign in to comment.