Skip to content

Commit b4dbd84

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 5318325 commit b4dbd84

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

@@ -309,7 +309,7 @@ def get_oldest_and_newest_rev(
309309

310310
tags_range = get_smart_tag_range(tags, newest=newest_tag, oldest=oldest_tag)
311311
if not tags_range:
312-
return None, None
312+
raise NoCommitsFoundError("Could not find a valid revision range.")
313313

314314
oldest_rev: Optional[str] = tags_range[-1].name
315315
newest_rev = newest_tag

tests/commands/test_changelog_command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def test_changelog_from_rev_latest_version_from_arg(
633633
def test_changelog_from_rev_single_version_not_found(
634634
mocker, config_path, changelog_path
635635
):
636+
"""Provides an invalid revision ID to changelog command"""
636637
with open(config_path, "a") as f:
637638
f.write('tag_format = "$version"\n')
638639

@@ -657,12 +658,13 @@ def test_changelog_from_rev_single_version_not_found(
657658
with pytest.raises(NoCommitsFoundError) as excinfo:
658659
cli.main()
659660

660-
assert "No commits found" in str(excinfo)
661+
assert "Could not find a valid revision" in str(excinfo)
661662

662663

663664
@pytest.mark.usefixtures("tmp_commitizen_project")
664665
@pytest.mark.freeze_time("2022-02-13")
665666
def test_changelog_from_rev_range_version_not_found(mocker, config_path):
667+
"""Provides an invalid end revision ID to changelog command"""
666668
with open(config_path, "a") as f:
667669
f.write('tag_format = "$version"\n')
668670

@@ -684,7 +686,7 @@ def test_changelog_from_rev_range_version_not_found(mocker, config_path):
684686
with pytest.raises(NoCommitsFoundError) as excinfo:
685687
cli.main()
686688

687-
assert "No commits found" in str(excinfo)
689+
assert "Could not find a valid revision" in str(excinfo)
688690

689691

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

0 commit comments

Comments
 (0)