From d570be1be359b07d9e59fdd5cebb6208db403a2e Mon Sep 17 00:00:00 2001 From: Gerard Salvatella Date: Sun, 27 Nov 2022 13:07:08 +0100 Subject: [PATCH] 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 https://github.com/commitizen-tools/commitizen/issues/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 https://github.com/commitizen-tools/commitizen/issues/622 --- commitizen/commands/changelog.py | 2 +- tests/commands/test_changelog_command.py | 31 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 854060a867..aab613fffc 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -137,7 +137,7 @@ def __call__(self): ) start_rev = self._find_incremental_rev(latest_tag_version, tags) - if self.rev_range and self.tag_format: + if self.rev_range: start_rev, end_rev = changelog.get_oldest_and_newest_rev( tags, version=self.rev_range, diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index dc932bd405..c2fafd4552 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -659,6 +659,37 @@ def test_changelog_from_rev_single_version_not_found( assert "Could not find a valid revision" in str(excinfo) +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_range_default_tag_format( + mocker, config_path, changelog_path +): + """Checks that rev_range is calculated with the default (None) tag format""" + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + wait_for_tag() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + wait_for_tag() + + testargs = ["cz", "changelog", "0.3.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + with open(changelog_path, "r") as f: + out = f.read() + + assert "new file" not in out + + @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") def test_changelog_from_rev_range_version_not_found(mocker, config_path):