Title: feat(bump): add --merge-prerelease flag by bearomorphism · Pull Request #1968 · commitizen-tools/commitizen · GitHub
Open Graph Title: feat(bump): add --merge-prerelease flag by bearomorphism · Pull Request #1968 · commitizen-tools/commitizen
X Title: feat(bump): add --merge-prerelease flag by bearomorphism · Pull Request #1968 · commitizen-tools/commitizen
Description: Description Closes #1934. Why cz changelog already exposes a --merge-prerelease flag that overrides the changelog_merge_prerelease config setting for a single invocation. The same flag is missing on cz bump, even though cz bump --changelog runs 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 edit pyproject.toml for one bump and revert it, or run cz bump followed by a separate cz changelog --merge-prerelease. The original issue calls for parity: It would be great to enable/disable changelog_merge_prerelease when calling cz bump in combination with update_changelog_on_bump = true/--changelog. What changed File Change commitizen/cli.py New --merge-prerelease argument under the bump subcommand (mirrors the one under changelog). commitizen/commands/bump.py BumpArgs gains merge_prerelease: bool | None; Bump.__call__ forwards it into changelog_args only when explicitly set. docs/commands/bump.md New ### --merge-prerelease section. tests/commands/test_bump_command.py New parameterised test_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_*.md Three regression fixtures (one per prerelease variant). tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_*_bump_.txt Regenerated cz bump --help snapshots (one per supported Python). How it works The argparse argument uses action="store_true", default=None. The None default is intentional: it lets Bump.__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 embedded Changelog invocation falls back to self.config.settings["changelog_merge_prerelease"] exactly as before — no behaviour change. In Bump.__call__, merge_prerelease is injected into changelog_args only when is not None. Because Changelog.__init__ evaluates arguments.get("merge_prerelease") or self.config.settings["changelog_merge_prerelease"], omitting the key from changelog_args correctly preserves the legacy behaviour. Both code paths in Bump.__call__ that construct a Changelog (the changelog_to_stdout path and the regular file path) receive the changelog_args dict, so the new flag is effective in both modes. The flag has no effect unless cz bump actually generates a changelog (--changelog, --changelog-to-stdout, or update_changelog_on_bump = true); a no-op flag without --changelog matches cz changelog's behaviour and avoids surprises. Backward compatibility All existing config combinations behave identically when the flag is absent. BumpArgs.merge_prerelease: bool | None is additive on a total=False TypedDict. The full pre-existing bump test suite (134 non-GPG tests) and cz bump --help snapshot tests pass unchanged after regeneration. Checklist I have read the contributing guidelines Was generative AI tooling used to co-author this PR? Yes (please specify the tool below) Generated-by: Claude following the guidelines Code Changes Add test cases to all the changes you introduce Run uv run poe all locally to ensure this change passes linter check and tests (poe lint clean; 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) Manually test the changes (see "Steps to Test" below for the exact commands) Update the documentation for the changes Documentation Changes Added a ### --merge-prerelease section to docs/commands/bump.md Help-text snapshots regenerated via uv run poe test:regen Run uv run poe doc locally to ensure the documentation pages render correctly Check and fix any broken links (internal or external) Expected Behavior Scenario Outcome cz bump --changelog (no flag, changelog_merge_prerelease = false — default) Prereleases keep their own sections in the changelog (legacy behaviour). cz bump --changelog --merge-prerelease Prereleases between previous and new non-prerelease are collapsed into the new entry. cz bump --changelog with changelog_merge_prerelease = true in config Prereleases are merged (legacy behaviour). cz bump --merge-prerelease (no --changelog, no update_changelog_on_bump) Flag is a no-op; no changelog is generated. cz bump --changelog-to-stdout --merge-prerelease Stdout changelog also has prereleases merged. Steps to Test This Pull Request git fetch fork feat/1934-bump-merge-prerelease-flag git checkout fork/feat/1934-bump-merge-prerelease-flag # 1. Targeted regression test (3 new + 6 pre-existing parametrised cases). uv run pytest tests/commands/test_bump_command.py -k merge_prerelease -v # expected: 9 passed # 2. Full bump-command suite (sanity check that nothing else broke). uv run pytest tests/commands/test_bump_command.py -k 'not signed' -q # expected: 134 passed (GPG-signing tests are excluded on Windows) # 3. Help snapshots updated correctly. uv run pytest tests/commands/test_common_command.py -q # expected: 14 passed # 4. End-to-end smoke (optional, requires a temp git repo): mkdir -p /tmp/cz-1968 && cd /tmp/cz-1968 && git init -q echo '[tool.commitizen]\nname = "cz_conventional_commits"\nversion = "0.1.0"\nupdate_changelog_on_bump = true\ntag_format = "v$version"' > pyproject.toml git add . && git -c user.email=a@b -c user.name=t commit -qm "feat: a" uv run cz bump --yes -pr alpha # -> v0.2.0a0 git -c user.email=a@b -c user.name=t commit --allow-empty -qm "fix: b" uv run cz bump --yes --changelog --merge-prerelease # collapses 0.2.0a0 entry cat CHANGELOG.md # 0.2.0 should contain both feat:a and fix:b under it Additional Context Surfaced while triaging open issues in #1965. Reviewed by an internal claude-sonnet-4.6 code-review pass and by GitHub Copilot; both reported no findings.
Open Graph Description: Description Closes #1934. Why cz changelog already exposes a --merge-prerelease flag that overrides the changelog_merge_prerelease config setting for a single invocation. The same flag is missing o...
X Description: Description Closes #1934. Why cz changelog already exposes a --merge-prerelease flag that overrides the changelog_merge_prerelease config setting for a single invocation. The same flag is missing o...
Opengraph URL: https://github.com/commitizen-tools/commitizen/pull/1968
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:012b1c6b-8d03-cd94-1546-cf5a1c90d75d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 92EE:34ED9:8B0B8:C6EA6:6A4DFA2E |
| html-safe-nonce | 4c46385754af820c9f411c412b033d607a9b583f201b23c5eef62f33fb7140e5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MkVFOjM0RUQ5OjhCMEI4OkM2RUE2OjZBNERGQTJFIiwidmlzaXRvcl9pZCI6IjkwMjI2MTU0MDU5NzgzMTk0MDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c28e894eda6adb15f752712bb7c7f270211b7473aed897aa00637bcb70859701 |
| hovercard-subject-tag | pull_request:3654684045 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/commitizen-tools/commitizen/pull/1968/files |
| twitter:image | https://avatars.githubusercontent.com/u/26526132?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/26526132?s=400&v=4 |
| og:image:alt | Description Closes #1934. Why cz changelog already exposes a --merge-prerelease flag that overrides the changelog_merge_prerelease config setting for a single invocation. The same flag is missing o... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5818716c93c6a2925b815402541a32814e43a7b1261c322b0c2df75224289566 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/commitizen-tools/commitizen git https://github.com/commitizen-tools/commitizen.git |
| octolytics-dimension-user_id | 62252524 |
| octolytics-dimension-user_login | commitizen-tools |
| octolytics-dimension-repository_id | 106127589 |
| octolytics-dimension-repository_nwo | commitizen-tools/commitizen |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 106127589 |
| octolytics-dimension-repository_network_root_nwo | commitizen-tools/commitizen |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4314b1df11fa8a565684f3a72dc971e3785da365 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width