Skip to content

Commit dac6de0

Browse files
committed
fix(bump): raise non zero error code when there's no elegible commit to bump
1 parent 323c72e commit dac6de0

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

commitizen/commands/bump.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ def __call__(self): # noqa: C901
170170
out.write(information)
171171

172172
if increment is None and new_tag_version == current_tag_version:
173-
raise NoneIncrementExit()
173+
raise NoneIncrementExit(
174+
"[NO_COMMITS_TO_BUMP]\n"
175+
"The commits found are not elegible to be bumped"
176+
)
174177

175178
# Do not perform operations over files or git.
176179
if dry_run:

commitizen/exceptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class DryRunExit(ExpectedExit):
5454
pass
5555

5656

57-
class NoneIncrementExit(ExpectedExit):
58-
pass
57+
class NoneIncrementExit(CommitizenException):
58+
exit_code = ExitCode.NO_COMMITS_FOUND
5959

6060

6161
class NoCommitizenFoundException(CommitizenException):

tests/commands/test_bump_command.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from commitizen import cli, cmd, git
99
from commitizen.exceptions import (
1010
BumpTagFailedError,
11+
CommitizenException,
1112
CurrentVersionNotFoundError,
1213
DryRunExit,
14+
ExitCode,
1315
ExpectedExit,
1416
NoCommitsFoundError,
1517
NoneIncrementExit,
@@ -327,7 +329,7 @@ def test_none_increment_exit_should_be_a_class():
327329

328330

329331
def test_none_increment_exit_should_be_expected_exit_subclass():
330-
assert issubclass(NoneIncrementExit, ExpectedExit)
332+
assert issubclass(NoneIncrementExit, CommitizenException)
331333

332334

333335
def test_none_increment_exit_should_exist_in_bump():
@@ -339,7 +341,9 @@ def test_none_increment_exit_is_exception():
339341

340342

341343
@pytest.mark.usefixtures("tmp_commitizen_project")
342-
def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):
344+
def test_none_increment_should_not_call_git_tag_and_error_code_is_not_zero(
345+
mocker, tmp_commitizen_project
346+
):
343347
create_file_and_commit("test(test_get_all_droplets): fix bad comparison test")
344348
testargs = ["cz", "bump", "--yes"]
345349
mocker.patch.object(sys, "argv", testargs)
@@ -350,8 +354,12 @@ def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):
350354
git.tag = MagicMock(return_value=dummy_value)
351355

352356
with pytest.raises(NoneIncrementExit):
353-
cli.main()
354-
git.tag.assert_not_called()
357+
try:
358+
cli.main()
359+
except NoneIncrementExit as e:
360+
git.tag.assert_not_called()
361+
assert e.exit_code == ExitCode.NO_COMMITS_FOUND
362+
raise e
355363

356364
# restore pop stashed
357365
git.tag = stashed_git_tag

0 commit comments

Comments
 (0)