Skip to content

Commit 7d59bf4

Browse files
committed
fix: clarify allow-no-commit changelog behavior and docs
Align internal typing/forwarding for allow_no_commit, simplify the regression test setup, and document how changelog entries are generated during no-commit bumps. Made-with: Cursor
1 parent 0598e36 commit 7d59bf4

File tree

5 files changed

+14
-30
lines changed

5 files changed

+14
-30
lines changed

commitizen/commands/bump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def __call__(self) -> None:
333333
{
334334
**changelog_args, # type: ignore[typeddict-item]
335335
"file_name": self.file_name,
336-
"allow_no_commit": self.arguments["allow_no_commit"],
336+
"allow_no_commit": bool(self.arguments["allow_no_commit"]),
337337
},
338338
)
339339
changelog_cmd()

commitizen/commands/changelog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ChangelogArgs(TypedDict, total=False):
4343
extras: dict[str, Any]
4444
export_template: str
4545
during_version_bump: bool | None
46-
allow_no_commit: bool # --allow-no-commit is still invalid in the changelog command
46+
allow_no_commit: bool | None
4747

4848

4949
class Changelog:
@@ -125,7 +125,8 @@ def __init__(self, config: BaseConfig, arguments: ChangelogArgs) -> None:
125125
self.export_template_to = arguments.get("export_template")
126126

127127
self.during_version_bump: bool = arguments.get("during_version_bump") or False
128-
self.allow_no_commit: bool = arguments.get("allow_no_commit") or False
128+
# Internal flag used when changelog is invoked from `cz bump --allow-no-commit`.
129+
self.allow_no_commit: bool = bool(arguments.get("allow_no_commit"))
129130

130131
def _find_incremental_rev(self, latest_version: str, tags: Iterable[GitTag]) -> str:
131132
"""Try to find the 'start_rev'.

docs/commands/bump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ cz bump --allow-no-commit 2.0.0
473473
cz bump --allow-no-commit 2.0.0
474474
```
475475

476+
!!! note "Behavior with changelog updates"
477+
When `update_changelog_on_bump = true` (or `--changelog` is used), `cz bump --allow-no-commit` also generates a changelog entry even if there are no commits in the selected range.
478+
479+
This makes the new release visible in the changelog while still showing that no commit-based changes were included.
480+
476481
### `--tag-format`
477482

478483
`tag_format` and [version_scheme][version_scheme] are combined to make Git tag names from versions.

docs/commands/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Generates a changelog following the committing rules established.
44

5+
When changelog generation is triggered by `cz bump --allow-no-commit` (with `--changelog` or `update_changelog_on_bump = true`), Commitizen still creates a release entry even when no commits are found in the selected revision range.
6+
57
!!! tip
68
To create the changelog automatically on bump, add the setting [update_changelog_on_bump](../config/bump.md#update_changelog_on_bump)
79

tests/commands/test_bump_command.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,33 +1548,9 @@ def test_bump_allow_no_commit_issue(
15481548
util: UtilFixture,
15491549
) -> None:
15501550
"""Issue #1866: bump command called changelog command with allow_no_commit=True, but changelog command raised NoCommitsFoundError"""
1551-
tmp_commitizen_project = tmp_commitizen_project_initial(version="1.0.0")
1552-
with (tmp_commitizen_project / "pyproject.toml").open("w") as f:
1553-
f.write(
1554-
dedent(
1555-
r"""
1556-
[project]
1557-
name = "abc"
1558-
version = "4.14.0"
1559-
1560-
[tool.commitizen]
1561-
name = "cz_customize"
1562-
tag_format = "$version"
1563-
version_scheme = "semver2"
1564-
version_provider = "pep621"
1565-
update_changelog_on_bump = true
1566-
1567-
[tool.commitizen.customize]
1568-
bump_pattern = '^(feat|fix|ci|build|perf|refactor|chore|remove|style|test)'
1569-
bump_map = {feat = "MINOR", fix = "PATCH", ci = "PATCH", build = "PATCH", perf = "PATCH", refactor = "PATCH", chore = "PATCH", remove = "PATCH", style = "PATCH", test = "PATCH" }
1570-
schema_pattern = "(build|bump|chore|ci|dev|docs|feat|fix|perf|refactor|remove|style|test):(\\s.*)"
1571-
commit_parser = "^(?P<change_type>build|bump|chore|ci|dev|docs|feat|fix|perf|refactor|remove|style|test):\\s(?P<message>.*)?"
1572-
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"}
1573-
change_type_order = ["BREAKING CHANGE", "New Features", "Bug Fixes", "Performance Improvements", "Refactoring", "General Improvements", "Removed", "Stylistic Changes", "Testing", "Build"]
1574-
changelog_pattern = "^(build|chore|feat|fix|perf|refactor|remove|style|test)"
1575-
"""
1576-
)
1577-
)
1551+
tmp_commitizen_project_initial(
1552+
version="1.0.0", config_extra="update_changelog_on_bump = true\n"
1553+
)
15781554
util.run_cli("bump", "--yes", "--allow-no-commit", "--prerelease", "beta")
15791555
util.run_cli(
15801556
"bump", "--allow-no-commit", "--prerelease", "rc"

0 commit comments

Comments
 (0)