diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 4f2a0d3981..70dcad263f 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -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: diff --git a/commitizen/exceptions.py b/commitizen/exceptions.py index 8293688715..218534c730 100644 --- a/commitizen/exceptions.py +++ b/commitizen/exceptions.py @@ -54,8 +54,8 @@ class DryRunExit(ExpectedExit): pass -class NoneIncrementExit(ExpectedExit): - pass +class NoneIncrementExit(CommitizenException): + exit_code = ExitCode.NO_COMMITS_FOUND class NoCommitizenFoundException(CommitizenException): diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 8508c66eee..b5c7b6b122 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -8,8 +8,10 @@ from commitizen import cli, cmd, git from commitizen.exceptions import ( BumpTagFailedError, + CommitizenException, CurrentVersionNotFoundError, DryRunExit, + ExitCode, ExpectedExit, NoCommitsFoundError, NoneIncrementExit, @@ -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(): @@ -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) @@ -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