Skip to content

fix(bump): pre and post bump hooks were failing when an increment was provided (fix #1004) #1007

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
Mar 7, 2024
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
3 changes: 2 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def __call__(self) -> None: # noqa: C901
scheme=self.scheme,
)

is_initial = self.is_initial_tag(current_tag_version, is_yes)

# If user specified changelog_to_stdout, they probably want the
# changelog to be generated as well, this is the most intuitive solution
self.changelog = self.changelog or bool(self.changelog_to_stdout)
Expand All @@ -223,7 +225,6 @@ def __call__(self) -> None: # noqa: C901
) from exc
else:
if increment is None:
is_initial = self.is_initial_tag(current_tag_version, is_yes)
if is_initial:
commits = git.get_commits()
else:
Expand Down
23 changes: 23 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,29 @@ def test_bump_with_pre_bump_hooks(
)


def test_bump_with_hooks_and_increment(mocker: MockFixture, tmp_commitizen_project):
pre_bump_hook = "scripts/pre_bump_hook.sh"
post_bump_hook = "scripts/post_bump_hook.sh"

tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml")
tmp_commitizen_cfg_file.write(
f"{tmp_commitizen_cfg_file.read()}\n"
f'pre_bump_hooks = ["{pre_bump_hook}"]\n'
f'post_bump_hooks = ["{post_bump_hook}"]\n'
)

run_mock = mocker.Mock()
mocker.patch.object(hooks, "run", run_mock)

create_file_and_commit("test: some test")
testargs = ["cz", "bump", "--yes", "--increment", "MINOR"]
mocker.patch.object(sys, "argv", testargs)
cli.main()

tag_exists = git.tag_exist("0.2.0")
assert tag_exists is True


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_manual_version_disallows_prerelease_offset(mocker):
create_file_and_commit("feat: new file")
Expand Down