Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4b7c175

Browse files
authored
Merge pull request #284 from christian-hawk/christian-hawk-patch
fix(commands/bump): Add NoneIncrementExit to avoid git fatal error
2 parents 5c0dd54 + 6370be0 commit 4b7c175

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

commitizen/commands/bump.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
DryRunExit,
1313
ExpectedExit,
1414
NoCommitsFoundError,
15+
NoneIncrementExit,
1516
NoPatternMapError,
1617
NotAGitProjectError,
1718
NoVersionSpecifiedError,
@@ -128,6 +129,9 @@ def __call__(self): # noqa: C901
128129
f"increment detected: {increment}\n"
129130
)
130131

132+
if increment is None and new_tag_version == current_tag_version:
133+
raise NoneIncrementExit()
134+
131135
# Do not perform operations over files or git.
132136
if dry_run:
133137
raise DryRunExit()

commitizen/commands/init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __call__(self):
4747
def _ask_config_path(self) -> str:
4848
name = questionary.select(
4949
"Please choose a supported config file: (default: pyproject.toml)",
50-
choices=config_files,
50+
choices=config_files, # type: ignore
5151
default="pyproject.toml",
5252
style=self.cz.style,
5353
).ask()
@@ -79,7 +79,7 @@ def _ask_tag(self) -> str:
7979

8080
latest_tag = questionary.select(
8181
"Please choose the latest tag: ",
82-
choices=get_tag_names(),
82+
choices=get_tag_names(), # type: ignore
8383
style=self.cz.style,
8484
).ask()
8585

commitizen/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class DryRunExit(ExpectedExit):
5353
pass
5454

5555

56+
class NoneIncrementExit(ExpectedExit):
57+
pass
58+
59+
5660
class NoCommitizenFoundException(CommitizenException):
5761
exit_code = ExitCode.NO_COMMITIZEN_FOUND
5862

commitizen/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_latest_tag_name() -> Optional[str]:
123123
return c.out.strip()
124124

125125

126-
def get_tag_names() -> Optional[List[str]]:
126+
def get_tag_names() -> List[Optional[str]]:
127127
c = cmd.run("git tag --list")
128128
if c.err:
129129
return []

tests/commands/test_bump_command.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import inspect
12
import sys
3+
from unittest.mock import MagicMock
24

35
import pytest
46

7+
import commitizen.commands.bump as bump
58
from commitizen import cli, cmd, git
69
from commitizen.exceptions import (
710
BumpTagFailedError,
811
CurrentVersionNotFoundError,
912
DryRunExit,
1013
ExpectedExit,
1114
NoCommitsFoundError,
15+
NoneIncrementExit,
1216
NoPatternMapError,
1317
NotAGitProjectError,
1418
NoVersionSpecifiedError,
@@ -262,3 +266,38 @@ def test_bump_in_non_git_project(tmpdir, config, mocker):
262266
with pytest.raises(NotAGitProjectError):
263267
with pytest.raises(ExpectedExit):
264268
cli.main()
269+
270+
271+
def test_none_increment_exit_should_be_a_class():
272+
assert inspect.isclass(NoneIncrementExit)
273+
274+
275+
def test_none_increment_exit_should_be_expected_exit_subclass():
276+
assert issubclass(NoneIncrementExit, ExpectedExit)
277+
278+
279+
def test_none_increment_exit_should_exist_in_bump():
280+
assert hasattr(bump, "NoneIncrementExit")
281+
282+
283+
def test_none_increment_exit_is_exception():
284+
assert bump.NoneIncrementExit == NoneIncrementExit
285+
286+
287+
@pytest.mark.usefixtures("tmp_commitizen_project")
288+
def test_none_increment_should_not_call_git_tag(mocker, tmp_commitizen_project):
289+
create_file_and_commit("test(test_get_all_droplets): fix bad comparison test")
290+
testargs = ["cz", "bump", "--yes"]
291+
mocker.patch.object(sys, "argv", testargs)
292+
293+
# stash git.tag for later restore
294+
stashed_git_tag = git.tag
295+
dummy_value = git.tag("0.0.2")
296+
git.tag = MagicMock(return_value=dummy_value)
297+
298+
with pytest.raises(NoneIncrementExit):
299+
cli.main()
300+
git.tag.assert_not_called()
301+
302+
# restore pop stashed
303+
git.tag = stashed_git_tag

tests/test_git.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import inspect
2+
from typing import List, Optional
3+
14
import pytest
25

36
from commitizen import git
@@ -68,3 +71,9 @@ def test_get_commits_author_and_email():
6871

6972
assert commit.author is not ""
7073
assert "@" in commit.author_email
74+
75+
76+
def test_get_tag_names_has_correct_arrow_annotation():
77+
arrow_annotation = inspect.getfullargspec(git.get_tag_names).annotations["return"]
78+
79+
assert arrow_annotation == List[Optional[str]]

0 commit comments

Comments
 (0)