Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ def __call__(self) -> None:

changelog_cmd = Changelog(
self.config,
{**changelog_args, "file_name": self.file_name}, # type: ignore[typeddict-item]
{
**changelog_args, # type: ignore[typeddict-item]
"file_name": self.file_name,
"allow_no_commit": self.arguments["allow_no_commit"],
},
)
changelog_cmd()
changelog_file_name = changelog_cmd.file_name
Expand Down
8 changes: 6 additions & 2 deletions commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ChangelogArgs(TypedDict, total=False):
extras: dict[str, Any]
export_template: str
during_version_bump: bool | None
allow_no_commit: bool # --allow-no-commit is still invalid in the changelog command


class Changelog:
Expand Down Expand Up @@ -124,6 +125,7 @@ def __init__(self, config: BaseConfig, arguments: ChangelogArgs) -> None:
self.export_template_to = arguments.get("export_template")

self.during_version_bump: bool = arguments.get("during_version_bump") or False
self.allow_no_commit: bool = arguments.get("allow_no_commit") or False

def _find_incremental_rev(self, latest_version: str, tags: Iterable[GitTag]) -> str:
"""Try to find the 'start_rev'.
Expand Down Expand Up @@ -255,8 +257,10 @@ def __call__(self) -> None:
changelog_meta.unreleased_end = latest_full_release_info.index + 1

commits = git.get_commits(start=start_rev, end=end_rev, args="--topo-order")
if not commits and (
self.current_version is None or not self.current_version.is_prerelease
if (
not self.allow_no_commit
and not commits
and (self.current_version is None or not self.current_version.is_prerelease)
):
raise NoCommitsFoundError("No commits found")

Expand Down
39 changes: 39 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,3 +1540,42 @@ def test_changelog_merge_preserves_header(
out = changelog_path.read_text()

file_regression.check(out, extension=".md")


@pytest.mark.freeze_time("2025-01-01")
def test_bump_allow_no_commit_issue(
tmp_commitizen_project_initial,
util: UtilFixture,
) -> None:
"""Issue #1866: bump command called changelog command with allow_no_commit=True, but changelog command raised NoCommitsFoundError"""
tmp_commitizen_project = tmp_commitizen_project_initial(version="1.0.0")
with (tmp_commitizen_project / "pyproject.toml").open("w") as f:
f.write(
dedent(
r"""
[project]
name = "abc"
version = "4.14.0"

[tool.commitizen]
name = "cz_customize"
tag_format = "$version"
version_scheme = "semver2"
version_provider = "pep621"
update_changelog_on_bump = true

[tool.commitizen.customize]
bump_pattern = '^(feat|fix|ci|build|perf|refactor|chore|remove|style|test)'
bump_map = {feat = "MINOR", fix = "PATCH", ci = "PATCH", build = "PATCH", perf = "PATCH", refactor = "PATCH", chore = "PATCH", remove = "PATCH", style = "PATCH", test = "PATCH" }
schema_pattern = "(build|bump|chore|ci|dev|docs|feat|fix|perf|refactor|remove|style|test):(\\s.*)"
commit_parser = "^(?P<change_type>build|bump|chore|ci|dev|docs|feat|fix|perf|refactor|remove|style|test):\\s(?P<message>.*)?"
change_type_map = {"feat" = "New Features", "fix" = "Bug Fixes", "perf" = "Performance Improvements", "refactor" = "Refactoring", "chore" = "General Improvements", "remove" = "Removed", "style" = "Stylistic Changes", "test" = "Testing", "build" = "Build"}
change_type_order = ["BREAKING CHANGE", "New Features", "Bug Fixes", "Performance Improvements", "Refactoring", "General Improvements", "Removed", "Stylistic Changes", "Testing", "Build"]
changelog_pattern = "^(build|chore|feat|fix|perf|refactor|remove|style|test)"
"""
)
)
util.run_cli("bump", "--yes", "--allow-no-commit", "--prerelease", "beta")
util.run_cli(
"bump", "--allow-no-commit", "--prerelease", "rc"
) # Failed because the bump command called changelog command