Skip to content
Open
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
2 changes: 1 addition & 1 deletion commitizen/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def normalize_tag(
version = self.scheme(version) if isinstance(version, str) else version
tag_format = tag_format or self.tag_format

major, minor, patch = version.release
major, minor, patch = (list(version.release) + [0, 0, 0])[:3]
prerelease = version.prerelease or ""

t = Template(tag_format)
Expand Down
44 changes: 44 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ def test_bump_invalid_manual_version_raises_exception(mocker, manual_version):
"0.1.1",
"0.2.0",
"1.0.0",
"1.2",
"1",
],
)
def test_bump_manual_version(mocker, manual_version):
Expand Down Expand Up @@ -966,6 +968,48 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
assert expected_error_message in str(excinfo.value)


def test_bump_version_with_single_component_in_config(
tmp_commitizen_project_initial, mocker: MockFixture
):
tmp_commitizen_project = tmp_commitizen_project_initial(version="1")

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)

cli.main()

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

for version_file in [
tmp_commitizen_project.join("__version__.py"),
tmp_commitizen_project.join("pyproject.toml"),
]:
with open(version_file) as f:
assert "1.1.0" in f.read()


def test_bump_version_with_two_components_in_config(
tmp_commitizen_project_initial, mocker: MockFixture
):
tmp_commitizen_project = tmp_commitizen_project_initial(version="1.2")

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)

cli.main()

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

for version_file in [
tmp_commitizen_project.join("__version__.py"),
tmp_commitizen_project.join("pyproject.toml"),
]:
with open(version_file) as f:
assert "1.3.0" in f.read()


@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
def test_bump_with_pre_bump_hooks(
commit_msg, mocker: MockFixture, tmp_commitizen_project
Expand Down