Skip to content

Commit 08d280e

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 08d280e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,35 @@ 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(mocker, config_path, changelog_path):
665+
"""Checks that rev_range is calculated with the default (None) tag format"""
666+
# create commit and tag
667+
create_file_and_commit("feat: new file")
668+
testargs = ["cz", "bump", "--yes"]
669+
mocker.patch.object(sys, "argv", testargs)
670+
cli.main()
671+
wait_for_tag()
672+
673+
create_file_and_commit("feat: after 0.2.0")
674+
create_file_and_commit("feat: another feature")
675+
676+
testargs = ["cz", "bump", "--yes"]
677+
mocker.patch.object(sys, "argv", testargs)
678+
cli.main()
679+
wait_for_tag()
680+
681+
testargs = ["cz", "changelog", "0.3.0"]
682+
mocker.patch.object(sys, "argv", testargs)
683+
cli.main()
684+
685+
with open(changelog_path, "r") as f:
686+
out = f.read()
687+
688+
assert "new file" not in out
689+
690+
662691
@pytest.mark.usefixtures("tmp_commitizen_project")
663692
@pytest.mark.freeze_time("2022-02-13")
664693
def test_changelog_from_rev_range_version_not_found(mocker, config_path):

0 commit comments

Comments
 (0)