Skip to content

fix(bump): preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog#1850

Merged
bearomorphism merged 8 commits intocommitizen-tools:masterfrom
edgarrmondragon:fix/bump-changelog-merge-pre-removes-header
Feb 7, 2026
Merged

fix(bump): preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog#1850
bearomorphism merged 8 commits intocommitizen-tools:masterfrom
edgarrmondragon:fix/bump-changelog-merge-pre-removes-header

Conversation

@edgarrmondragon
Copy link
Contributor

@edgarrmondragon edgarrmondragon commented Feb 5, 2026

Description

Fixes a regression introduced in v4.11.3 (370ac9d, #1700) where using cz bump --changelog with changelog_merge_prerelease = true results in the header of the existing changelog file being removed.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: Claude Code 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
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external)

Expected Behavior

Steps to Test This Pull Request

Additional Context

@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.91%. Comparing base (2cfb8c6) to head (b9ed2c9).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1850      +/-   ##
==========================================
- Coverage   97.99%   97.91%   -0.08%     
==========================================
  Files          60       60              
  Lines        2691     2692       +1     
==========================================
- Hits         2637     2636       -1     
- Misses         54       56       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
…rerelease` is used with `cz bump --changelog`

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
…rerelease` is used with `cz bump --changelog`, and no prereleases exist

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon edgarrmondragon force-pushed the fix/bump-changelog-merge-pre-removes-header branch from 0c3bced to 778edcb Compare February 5, 2026 02:12
@edgarrmondragon edgarrmondragon marked this pull request as ready for review February 5, 2026 02:17
edgarrmondragon added a commit to meltano/meltano that referenced this pull request Feb 5, 2026
<!--

Please, go through these steps when you submit a PR.

1. Make sure your branch is not protected. In particular, avoid making
PRs from the `main` branch of your fork.

2. Give a descriptive title to your PR. We use semantic titles, and the
accepted types and scopes are listed in
https://github.com/meltano/meltano/blob/main/.github/semantic.yml.

   A good title should look like this:

   ```
feat(cli): The `meltano run` command now accepts a `--timeout` option to
limit the time it runs
   ```

3. Provide a description of your changes.

4. Put "Closes #XXXX" in your comment to auto-close the issue that your
PR fixes (if such).

-->

## Description

<!-- Describe the changes introduced by this PR -->

## Related Issues

* commitizen-tools/commitizen#1850

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
edgarrmondragon added a commit to meltano/meltano that referenced this pull request Feb 5, 2026
<!--

Please, go through these steps when you submit a PR.

1. Make sure your branch is not protected. In particular, avoid making
PRs from the `main` branch of your fork.

2. Give a descriptive title to your PR. We use semantic titles, and the
accepted types and scopes are listed in
https://github.com/meltano/meltano/blob/main/.github/semantic.yml.

   A good title should look like this:

   ```
feat(cli): The `meltano run` command now accepts a `--timeout` option to
limit the time it runs
   ```

3. Provide a description of your changes.

4. Put "Closes #XXXX" in your comment to auto-close the issue that your
PR fixes (if such).

-->

## Description

<!-- Describe the changes introduced by this PR -->

## Related Issues

* commitizen-tools/commitizen#1850

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Copy link
Collaborator

@bearomorphism bearomorphism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for reporting this issue and providing a fix! A few nits

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon edgarrmondragon force-pushed the fix/bump-changelog-merge-pre-removes-header branch from 227e12e to 397abe7 Compare February 6, 2026 20:28
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon
Copy link
Contributor Author

Thanks for the review @bearomorphism, this is ready for another pass.

@bearomorphism
Copy link
Collaborator

Thanks!

Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@bearomorphism bearomorphism changed the title fix(bump): Preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog fix(bump): preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog Feb 7, 2026
@bearomorphism bearomorphism enabled auto-merge (squash) February 7, 2026 01:43
@edgarrmondragon
Copy link
Contributor Author

Thanks for the feedback again @bearomorphism!

In the latest commit I put all the relevant cases to my usecase in a single parametrized test:

  1. The prerelease is merged into the final
  2. The prerelease is preserved
  3. There's no prerelase

In all cases I'm interested in the changelog header is preserved 😀

@bearomorphism bearomorphism merged commit 4ed2653 into commitizen-tools:master Feb 7, 2026
20 checks passed
@bearomorphism bearomorphism requested review from Copilot and removed request for Lee-W, noirbizarre and woile February 7, 2026 01:51
@edgarrmondragon edgarrmondragon deleted the fix/bump-changelog-merge-pre-removes-header branch February 7, 2026 01:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in Commitizen’s bump + changelog generation where enabling changelog_merge_prerelease could remove the existing changelog header during cz bump --changelog.

Changes:

  • Update changelog generation logic to preserve existing header content when prerelease-merging is enabled.
  • Add regression test coverage for preserving the changelog header across prerelease/no-prerelease and merge/no-merge scenarios.
  • Add file-regression snapshots for the new header-preservation test cases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
commitizen/commands/changelog.py Adjusts prerelease-merge metadata handling so incremental writes don’t drop the preamble/header.
tests/commands/test_bump_command.py Adds a new parametrized regression test ensuring headers are preserved under different prerelease/merge combinations.
tests/commands/test_bump_command/test_changelog_merge_preserves_header_without_prerelease_.md Snapshot for header-preservation case with no prerelease involved.
tests/commands/test_bump_command/test_changelog_merge_preserves_header_with_prerelease_no_merge_.md Snapshot for prerelease present but merging disabled.
tests/commands/test_bump_command/test_changelog_merge_preserves_header_with_prerelease_merge_.md Snapshot for prerelease present and merging enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1505 to +1510
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_deprecate_files_only(util: UtilFixture):
util.create_file_and_commit("feat: new file")
with (
pytest.warns(DeprecationWarning, match=r".*--files-only.*deprecated"),
pytest.raises(ExpectedExit),
):
util.run_cli("bump", "--yes", "--files-only")
@pytest.mark.freeze_time("2025-01-01")
def test_changelog_merge_preserves_header(
mocker: MockFixture,
util: UtilFixture,
changelog_path: Path,
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing deprecation test for --files-only (test_bump_deprecate_files_only) was removed in this hunk and doesn’t appear elsewhere in the test suite. This drops coverage for the expected DeprecationWarning + ExpectedExit behavior; please restore the test (or add an equivalent) alongside the new changelog header regression tests.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fault I didn't see this section...

Copy link
Contributor Author

@edgarrmondragon edgarrmondragon Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry about that!

I saw the drop in coverage for --files-only but didn't think more of that 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants