Skip to content

Commit 7d2e857

Browse files
committed
feat(tags): enable version schemes with less than 3 components
1 parent c0da2e6 commit 7d2e857

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

commitizen/tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def normalize_tag(
228228
version = self.scheme(version) if isinstance(version, str) else version
229229
tag_format = tag_format or self.tag_format
230230

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

234234
t = Template(tag_format)

tests/commands/test_bump_command.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,8 @@ def test_bump_invalid_manual_version_raises_exception(mocker, manual_version):
937937
"0.1.1",
938938
"0.2.0",
939939
"1.0.0",
940+
"1.2",
941+
"1",
940942
],
941943
)
942944
def test_bump_manual_version(mocker, manual_version):
@@ -966,6 +968,48 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
966968
assert expected_error_message in str(excinfo.value)
967969

968970

971+
def test_bump_version_with_single_component_in_config(
972+
tmp_commitizen_project_initial, mocker: MockFixture
973+
):
974+
tmp_commitizen_project = tmp_commitizen_project_initial(version="1")
975+
976+
testargs = ["cz", "bump", "--yes"]
977+
mocker.patch.object(sys, "argv", testargs)
978+
979+
cli.main()
980+
981+
tag_exists = git.tag_exist("1.1.0")
982+
assert tag_exists is True
983+
984+
for version_file in [
985+
tmp_commitizen_project.join("__version__.py"),
986+
tmp_commitizen_project.join("pyproject.toml"),
987+
]:
988+
with open(version_file) as f:
989+
assert "1.1.0" in f.read()
990+
991+
992+
def test_bump_version_with_two_components_in_config(
993+
tmp_commitizen_project_initial, mocker: MockFixture
994+
):
995+
tmp_commitizen_project = tmp_commitizen_project_initial(version="1.2")
996+
997+
testargs = ["cz", "bump", "--yes"]
998+
mocker.patch.object(sys, "argv", testargs)
999+
1000+
cli.main()
1001+
1002+
tag_exists = git.tag_exist("1.3.0")
1003+
assert tag_exists is True
1004+
1005+
for version_file in [
1006+
tmp_commitizen_project.join("__version__.py"),
1007+
tmp_commitizen_project.join("pyproject.toml"),
1008+
]:
1009+
with open(version_file) as f:
1010+
assert "1.3.0" in f.read()
1011+
1012+
9691013
@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
9701014
def test_bump_with_pre_bump_hooks(
9711015
commit_msg, mocker: MockFixture, tmp_commitizen_project

0 commit comments

Comments
 (0)