Skip to content

Commit

Permalink
fix(bump): manual version bump if prerelease offset is configured
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
ckagerer authored and Lee-W committed Feb 18, 2025
1 parent 295f975 commit d831c99
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 23 deletions.
5 changes: 0 additions & 5 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion docs/commands/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
17 changes: 0 additions & 17 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d831c99

Please sign in to comment.