Skip to content

fix(bump): raise non zero error code when there's no elegible commit to bump #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2022
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
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