Skip to content

Commit 107fa25

Browse files
committed
fix(commands/bump): use return_code in commands used by bump
1 parent bf16b51 commit 107fa25

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

commitizen/commands/bump.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ def __call__(self): # noqa: C901
154154

155155
self.config.set_key("version", new_version.public)
156156
c = git.commit(message, args=self._get_commit_args())
157-
if c.err:
157+
if c.return_code != 0:
158158
raise BumpCommitFailedError(f'git.commit error: "{c.err.strip()}"')
159159
c = git.tag(new_tag_version)
160-
if c.err:
160+
if c.return_code != 0:
161161
raise BumpTagFailedError(c.err)
162162
out.success("Done!")
163163

tests/commands/test_bump_command.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from commitizen import cli, cmd, git
66
from commitizen.exceptions import (
7-
BumpCommitFailedError,
7+
BumpTagFailedError,
88
CurrentVersionNotFoundError,
99
DryRunExit,
1010
ExpectedExit,
@@ -71,6 +71,7 @@ def test_bump_command(mocker):
7171

7272
@pytest.mark.usefixtures("tmp_commitizen_project")
7373
def test_bump_on_git_with_hooks_no_verify_disabled(mocker):
74+
"""Bump commit without --no-verify"""
7475
cmd.run("mkdir .git/hooks")
7576
with open(".git/hooks/pre-commit", "w") as f:
7677
f.write("#!/usr/bin/env bash\n" 'echo "0.1.0"')
@@ -82,10 +83,29 @@ def test_bump_on_git_with_hooks_no_verify_disabled(mocker):
8283
testargs = ["cz", "bump", "--yes"]
8384
mocker.patch.object(sys, "argv", testargs)
8485

85-
with pytest.raises(BumpCommitFailedError) as excinfo:
86-
cli.main()
86+
cli.main()
87+
88+
tag_exists = git.tag_exist("0.2.0")
89+
assert tag_exists is True
90+
91+
92+
@pytest.mark.usefixtures("tmp_commitizen_project")
93+
def test_bump_tag_exists_raises_exception(mocker):
94+
cmd.run("mkdir .git/hooks")
95+
with open(".git/hooks/post-commit", "w") as f:
96+
f.write("#!/usr/bin/env bash\n" "exit 9")
97+
cmd.run("chmod +x .git/hooks/post-commit")
98+
99+
# MINOR
100+
create_file_and_commit("feat: new file")
101+
git.tag("0.2.0")
87102

88-
assert 'git.commit error: "0.1.0"' in str(excinfo.value)
103+
testargs = ["cz", "bump", "--yes"]
104+
mocker.patch.object(sys, "argv", testargs)
105+
106+
with pytest.raises(BumpTagFailedError) as excinfo:
107+
cli.main()
108+
assert "fatal: tag '0.2.0' already exists" in str(excinfo.value)
89109

90110

91111
@pytest.mark.usefixtures("tmp_commitizen_project")

0 commit comments

Comments
 (0)