feat(bump): add --merge-prerelease flag#1968
feat(bump): add --merge-prerelease flag#1968bearomorphism wants to merge 1 commit intocommitizen-tools:masterfrom
Conversation
Closes commitizen-tools#1934. Adds a `--merge-prerelease` CLI flag to `cz bump` that mirrors the existing flag of `cz changelog`. When passed, it overrides the `changelog_merge_prerelease` setting for a single bump invocation, which is useful when you want to keep prerelease entries in the changelog by default but collapse them on a release bump. The implementation adds the flag to `commitizen/cli.py`, threads it through the `BumpArgs` TypedDict, and forwards it to the embedded `Changelog` invocation in `commands/bump.py`. The pre-existing `Changelog` argument plumbing (`merge_prerelease` -> `tag_rules. merge_prereleases`) is unchanged. Also adds a parameterised test that proves the CLI flag enables merging even when the config setting is left at its default (`false`), reusing the existing fixture content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1968 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 61 61
Lines 2779 2783 +4
=======================================
+ Hits 2730 2734 +4
Misses 49 49 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
Adds a --merge-prerelease CLI flag to cz bump to mirror cz changelog --merge-prerelease, enabling users to collapse prerelease changelog entries into the next non-prerelease entry for a single bump invocation while preserving config-driven behavior when the flag is absent.
Changes:
- Introduce
merge_prerelease: bool | Noneto bump arguments and forward it to the embeddedChangelogcall only when explicitly set. - Add regression tests and fixtures validating merged prerelease behavior across
rc|alpha|beta. - Update bump command documentation and help-text snapshots to include the new flag.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| commitizen/cli.py | Adds cz bump --merge-prerelease argument with tri-state default (None) and help text. |
| commitizen/commands/bump.py | Plumbs merge_prerelease through to Changelog invocation when provided. |
| docs/commands/bump.md | Documents --merge-prerelease usage and its relationship to changelog_merge_prerelease. |
| tests/commands/test_bump_command.py | Adds a parameterized test ensuring the CLI flag merges prereleases during a release bump. |
| tests/commands/test_bump_command/test_changelog_cli_flag_merge_prerelease_{rc,alpha,beta}_.md | Adds expected changelog outputs for the new test. |
| tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_{10,11,12,13,14}bump.txt | Updates help snapshots to include the new option and description. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Closes #1934.
Why
cz changelogalready exposes a--merge-prereleaseflag that overrides thechangelog_merge_prereleaseconfig setting for a single invocation. The same flag is missing oncz bump, even thoughcz bump --changelogruns the same changelog generator under the hood. Users who want prerelease entries to live as separate sections in their changelog by default, but be merged into the release entry on the actual release bump, currently have to either editpyproject.tomlfor one bump and revert it, or runcz bumpfollowed by a separatecz changelog --merge-prerelease.The original issue calls for parity:
What changed
commitizen/cli.py--merge-prereleaseargument under thebumpsubcommand (mirrors the one underchangelog).commitizen/commands/bump.pyBumpArgsgainsmerge_prerelease: bool | None;Bump.__call__forwards it intochangelog_argsonly when explicitly set.docs/commands/bump.md### --merge-prereleasesection.tests/commands/test_bump_command.pytest_changelog_cli_flag_merge_prerelease[rc|alpha|beta]that exercises the flag without setting the config.tests/commands/test_bump_command/test_changelog_cli_flag_merge_prerelease_*.mdtests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_*_bump_.txtcz bump --helpsnapshots (one per supported Python).How it works
action="store_true", default=None. TheNonedefault is intentional: it letsBump.__call__distinguish "user did not pass the flag" from "user passed--no-merge-prerelease-equivalent" without a separate negation flag. When the flag is absent the embeddedChangeloginvocation falls back toself.config.settings["changelog_merge_prerelease"]exactly as before — no behaviour change.Bump.__call__,merge_prereleaseis injected intochangelog_argsonly whenis not None. BecauseChangelog.__init__evaluatesarguments.get("merge_prerelease") or self.config.settings["changelog_merge_prerelease"], omitting the key fromchangelog_argscorrectly preserves the legacy behaviour.Bump.__call__that construct aChangelog(thechangelog_to_stdoutpath and the regular file path) receive thechangelog_argsdict, so the new flag is effective in both modes.cz bumpactually generates a changelog (--changelog,--changelog-to-stdout, orupdate_changelog_on_bump = true); a no-op flag without--changelogmatchescz changelog's behaviour and avoids surprises.Backward compatibility
BumpArgs.merge_prerelease: bool | Noneis additive on atotal=FalseTypedDict.cz bump --helpsnapshot tests pass unchanged after regeneration.Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Claude following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and tests (poe lintclean; 134 non-GPG bump tests + 14 common-command help-text tests pass; the 4 GPG-signing test errors on Windows are pre-existing and unrelated to this change)Documentation Changes
### --merge-prereleasesection todocs/commands/bump.mduv run poe test:regenuv run poe doclocally to ensure the documentation pages render correctlyExpected Behavior
cz bump --changelog(no flag,changelog_merge_prerelease = false— default)cz bump --changelog --merge-prereleasecz bump --changelogwithchangelog_merge_prerelease = truein configcz bump --merge-prerelease(no--changelog, noupdate_changelog_on_bump)cz bump --changelog-to-stdout --merge-prereleaseSteps to Test This Pull Request
Additional Context
Surfaced while triaging open issues in #1965. Reviewed by an internal
claude-sonnet-4.6code-review pass and by GitHub Copilot; both reported no findings.