Skip to content

Commit d570be1

Browse files
gsalvatellaGerard Salvatella
authored and
Gerard Salvatella
committed
fix(changelog): allow rev range lookups without a tag format
The current default setting for `tag_format` is `None`. This is not a problem for the `bump` command, since the `normalize_tag` function defaults to `$version` when no `tag_format` is passed. However it is a problem for the `changelog` command, which seems to explicitly demand a `tag_format` in order to run a rev-range lookup. This creates issues like #622. Either a sane default needs to be set for `tag_format` or the restriction in `changelog` has to be uplifted. In this commit the latter has been chosen. A test is also implemented to check that `changelog` will always compute a rev range with the default tag format. Fixes #622
1 parent c07c147 commit d570be1

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

commitizen/commands/changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __call__(self):
137137
)
138138
start_rev = self._find_incremental_rev(latest_tag_version, tags)
139139

140-
if self.rev_range and self.tag_format:
140+
if self.rev_range:
141141
start_rev, end_rev = changelog.get_oldest_and_newest_rev(
142142
tags,
143143
version=self.rev_range,

tests/commands/test_changelog_command.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,37 @@ def test_changelog_from_rev_single_version_not_found(
659659
assert "Could not find a valid revision" in str(excinfo)
660660

661661

662+
@pytest.mark.usefixtures("tmp_commitizen_project")
663+
@pytest.mark.freeze_time("2022-02-13")
664+
def test_changelog_from_rev_range_default_tag_format(
665+
mocker, config_path, changelog_path
666+
):
667+
"""Checks that rev_range is calculated with the default (None) tag format"""
668+
# create commit and tag
669+
create_file_and_commit("feat: new file")
670+
testargs = ["cz", "bump", "--yes"]
671+
mocker.patch.object(sys, "argv", testargs)
672+
cli.main()
673+
wait_for_tag()
674+
675+
create_file_and_commit("feat: after 0.2.0")
676+
create_file_and_commit("feat: another feature")
677+
678+
testargs = ["cz", "bump", "--yes"]
679+
mocker.patch.object(sys, "argv", testargs)
680+
cli.main()
681+
wait_for_tag()
682+
683+
testargs = ["cz", "changelog", "0.3.0"]
684+
mocker.patch.object(sys, "argv", testargs)
685+
cli.main()
686+
687+
with open(changelog_path, "r") as f:
688+
out = f.read()
689+
690+
assert "new file" not in out
691+
692+
662693
@pytest.mark.usefixtures("tmp_commitizen_project")
663694
@pytest.mark.freeze_time("2022-02-13")
664695
def test_changelog_from_rev_range_version_not_found(mocker, config_path):

0 commit comments

Comments
 (0)