Skip to content

Commit dd5dfed

Browse files
noirbizarrewoile
authored andcommitted
fix(bump): pre and post bump hooks were failing when an increment was provided (fix #1004)
1 parent c0b7229 commit dd5dfed

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Diff for: commitizen/commands/bump.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def __call__(self) -> None: # noqa: C901
209209
scheme=self.scheme,
210210
)
211211

212+
is_initial = self.is_initial_tag(current_tag_version, is_yes)
213+
212214
# If user specified changelog_to_stdout, they probably want the
213215
# changelog to be generated as well, this is the most intuitive solution
214216
self.changelog = self.changelog or bool(self.changelog_to_stdout)
@@ -223,7 +225,6 @@ def __call__(self) -> None: # noqa: C901
223225
) from exc
224226
else:
225227
if increment is None:
226-
is_initial = self.is_initial_tag(current_tag_version, is_yes)
227228
if is_initial:
228229
commits = git.get_commits()
229230
else:

Diff for: tests/commands/test_bump_command.py

+23
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,29 @@ def test_bump_with_pre_bump_hooks(
10071007
)
10081008

10091009

1010+
def test_bump_with_hooks_and_increment(mocker: MockFixture, tmp_commitizen_project):
1011+
pre_bump_hook = "scripts/pre_bump_hook.sh"
1012+
post_bump_hook = "scripts/post_bump_hook.sh"
1013+
1014+
tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
1015+
tmp_commitizen_cfg_file.write(
1016+
f"{tmp_commitizen_cfg_file.read()}\n"
1017+
f'pre_bump_hooks = ["{pre_bump_hook}"]\n'
1018+
f'post_bump_hooks = ["{post_bump_hook}"]\n'
1019+
)
1020+
1021+
run_mock = mocker.Mock()
1022+
mocker.patch.object(hooks, "run", run_mock)
1023+
1024+
create_file_and_commit("test: some test")
1025+
testargs = ["cz", "bump", "--yes", "--increment", "MINOR"]
1026+
mocker.patch.object(sys, "argv", testargs)
1027+
cli.main()
1028+
1029+
tag_exists = git.tag_exist("0.2.0")
1030+
assert tag_exists is True
1031+
1032+
10101033
@pytest.mark.usefixtures("tmp_commitizen_project")
10111034
def test_bump_manual_version_disallows_prerelease_offset(mocker):
10121035
create_file_and_commit("feat: new file")

0 commit comments

Comments
 (0)