From dfd2fdfcd50e36788d0778aad4111539c1e6d054 Mon Sep 17 00:00:00 2001 From: Christian Kagerer Date: Mon, 17 Feb 2025 15:32:20 +0100 Subject: [PATCH] fix(bump): manual version bump if prerelease offset is configured If you use the prerelase offset in the .cz.toml, as in the following example, no bump with a manual version number is possible. The error occurs when bumping with manual version number: cz bump 9.8.7 --prerelease-offset cannot be combined with MANUAL_VERSION ```toml [tool.commitizen] changelog_incremental = true tag_format = "v$version" update_changelog_on_bump = true version = "1.2.0b13" prerelease_offset = 1 ``` --- commitizen/commands/bump.py | 5 ----- docs/commands/bump.md | 2 +- tests/commands/test_bump_command.py | 17 ----------------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index b82cac940..8e9f0f181 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -187,11 +187,6 @@ def __call__(self) -> None: # noqa: C901 "--major-version-zero cannot be combined with MANUAL_VERSION" ) - if prerelease_offset: - raise NotAllowed( - "--prerelease-offset cannot be combined with MANUAL_VERSION" - ) - if get_next: raise NotAllowed("--get-next cannot be combined with MANUAL_VERSION") diff --git a/docs/commands/bump.md b/docs/commands/bump.md index 49c6f0343..efdba7625 100644 --- a/docs/commands/bump.md +++ b/docs/commands/bump.md @@ -599,7 +599,7 @@ post_bump_hooks = [ ### `prerelease_offset` -Offset with which to start counting prereleses. +Offset with which to start counting prereleases. Defaults to: `0` diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 934c0b817..52e2defde 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -1041,23 +1041,6 @@ def test_bump_with_hooks_and_increment(mocker: MockFixture, tmp_commitizen_proje 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") - - manual_version = "0.2.0" - testargs = ["cz", "bump", "--yes", "--prerelease-offset", "42", manual_version] - mocker.patch.object(sys, "argv", testargs) - - with pytest.raises(NotAllowed) as excinfo: - cli.main() - - expected_error_message = ( - "--prerelease-offset cannot be combined with MANUAL_VERSION" - ) - assert expected_error_message in str(excinfo.value) - - @pytest.mark.usefixtures("tmp_git_project") def test_bump_use_version_provider(mocker: MockFixture): mock = mocker.MagicMock(name="provider")