Skip to content

Commit f15ecf1

Browse files
committed
refactor(changelog): fixes logic issue made evident by latest fix(git) commit
get_commits was calling git "git log None..None" in the event that a tag range is invalid. Raise exception sooner rather than later.
1 parent 7b70f9a commit f15ecf1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

commitizen/changelog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from commitizen import defaults
3737
from commitizen.bump import normalize_tag
38-
from commitizen.exceptions import InvalidConfigurationError
38+
from commitizen.exceptions import InvalidConfigurationError, NoCommitsFoundError
3939
from commitizen.git import GitCommit, GitTag
4040

4141
CATEGORIES = [
@@ -332,7 +332,7 @@ def get_oldest_and_newest_rev(
332332

333333
tags_range = get_smart_tag_range(tags, newest=newest_tag, oldest=oldest_tag)
334334
if not tags_range:
335-
return None, None
335+
raise NoCommitsFoundError("Could not find a valid revision range.")
336336

337337
oldest_rev: Optional[str] = tags_range[-1].name
338338
newest_rev = newest_tag

tests/commands/test_changelog_command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ def test_changelog_from_rev_latest_version_from_arg(
655655
def test_changelog_from_rev_single_version_not_found(
656656
mocker, config_path, changelog_path
657657
):
658+
"""Provides an invalid revision ID to changelog command"""
658659
with open(config_path, "a") as f:
659660
f.write('tag_format = "$version"\n')
660661

@@ -679,12 +680,13 @@ def test_changelog_from_rev_single_version_not_found(
679680
with pytest.raises(NoCommitsFoundError) as excinfo:
680681
cli.main()
681682

682-
assert "No commits found" in str(excinfo)
683+
assert "Could not find a valid revision" in str(excinfo)
683684

684685

685686
@pytest.mark.usefixtures("tmp_commitizen_project")
686687
@pytest.mark.freeze_time("2022-02-13")
687688
def test_changelog_from_rev_range_version_not_found(mocker, config_path):
689+
"""Provides an invalid end revision ID to changelog command"""
688690
with open(config_path, "a") as f:
689691
f.write('tag_format = "$version"\n')
690692

@@ -706,7 +708,7 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path):
706708
with pytest.raises(NoCommitsFoundError) as excinfo:
707709
cli.main()
708710

709-
assert "No commits found" in str(excinfo)
711+
assert "Could not find a valid revision" in str(excinfo)
710712

711713

712714
@pytest.mark.usefixtures("tmp_commitizen_project")

0 commit comments

Comments
 (0)