-
-
Notifications
You must be signed in to change notification settings - Fork 334
fix(bump): preserve existing changelog header when changelog_merge_prerelease is used with cz bump --changelog
#1850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
0c430ae
681a433
778edcb
fb214be
397abe7
fbee607
85b1f90
b9ed2c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1494,6 +1494,91 @@ def test_changelog_config_flag_merge_prerelease_only_prerelease_present( | |
| file_regression.check(out, extension=".md") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| @pytest.mark.freeze_time("2025-01-01") | ||
| def test_changelog_merge_prerelease_preserves_header( | ||
| mocker: MockFixture, | ||
| util: UtilFixture, | ||
| changelog_path: Path, | ||
|
Comment on lines
1505
to
+1510
|
||
| config_path: Path, | ||
| file_regression: FileRegressionFixture, | ||
| ): | ||
| """Test that merge_prerelease preserves existing changelog header.""" | ||
| with config_path.open("a") as f: | ||
| f.write("changelog_merge_prerelease = true\n") | ||
| f.write("update_changelog_on_bump = true\n") | ||
| f.write("annotated_tag = true\n") | ||
|
|
||
| # Create initial version with changelog that has a header | ||
| util.create_file_and_commit("irrelevant commit") | ||
| mocker.patch("commitizen.git.GitTag.date", "1970-01-01") | ||
| git.tag("0.1.0") | ||
|
|
||
| # Create a changelog with a header manually | ||
| changelog_path.write_text( | ||
| "# Changelog\n\nAll notable changes to this project will be documented here.\n\n## 0.1.0 (1970-01-01)\n" | ||
| ) | ||
|
|
||
| util.create_file_and_commit("feat: add new output") | ||
| util.create_file_and_commit("fix: output glitch") | ||
| util.run_cli("bump", "--prerelease", "alpha", "--yes") | ||
|
bearomorphism marked this conversation as resolved.
Outdated
|
||
|
|
||
| util.run_cli("bump", "--changelog") | ||
|
|
||
| with changelog_path.open() as f: | ||
| out = f.read() | ||
|
|
||
| # The header should be preserved | ||
| assert out.startswith("# Changelog\n") | ||
| assert "All notable changes to this project will be documented here." in out | ||
|
bearomorphism marked this conversation as resolved.
Outdated
|
||
| file_regression.check(out, extension=".md") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| @pytest.mark.freeze_time("2025-01-01") | ||
| def test_changelog_merge_prerelease_no_prereleases_to_merge( | ||
| mocker: MockFixture, | ||
| util: UtilFixture, | ||
| changelog_path: Path, | ||
| config_path: Path, | ||
| file_regression: FileRegressionFixture, | ||
| ): | ||
| """Test that merge_prerelease works correctly when there are no prereleases. | ||
|
|
||
| When changelog_merge_prerelease is enabled but there are no prereleases to merge, | ||
| the normal incremental changelog behavior should apply and the existing changelog | ||
| content should be preserved. | ||
| """ | ||
| with config_path.open("a") as f: | ||
| f.write("changelog_merge_prerelease = true\n") | ||
| f.write("update_changelog_on_bump = true\n") | ||
| f.write("annotated_tag = true\n") | ||
|
|
||
| # Create initial version with changelog that has a header | ||
| util.create_file_and_commit("feat: initial feature") | ||
| mocker.patch("commitizen.git.GitTag.date", "1970-01-01") | ||
| git.tag("0.1.0") | ||
|
|
||
| # Create a changelog with a header manually | ||
| changelog_path.write_text( | ||
| "# Changelog\n\nAll notable changes.\n\n## 0.1.0 (1970-01-01)\n\n### Feat\n\n- initial feature\n" | ||
| ) | ||
|
|
||
| # Add new commits and do a regular bump (no prerelease) | ||
| util.create_file_and_commit("feat: add new output") | ||
| util.create_file_and_commit("fix: output glitch") | ||
| util.run_cli("bump", "--changelog") | ||
|
|
||
| with changelog_path.open() as f: | ||
| out = f.read() | ||
|
|
||
| # The header and existing content should be preserved | ||
| assert out.startswith("# Changelog\n") | ||
| assert "All notable changes." in out | ||
| assert "## 0.1.0 (1970-01-01)" in out | ||
|
edgarrmondragon marked this conversation as resolved.
Outdated
edgarrmondragon marked this conversation as resolved.
Outdated
|
||
| file_regression.check(out, extension=".md") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("tmp_commitizen_project") | ||
| def test_bump_deprecate_files_only(util: UtilFixture): | ||
| util.create_file_and_commit("feat: new file") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes. | ||
|
|
||
| ## 0.2.0 (2025-01-01) | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 (1970-01-01) | ||
|
|
||
| ### Feat | ||
|
|
||
| - initial feature |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented here. | ||
|
|
||
| ## 0.2.0 (2025-01-01) | ||
|
|
||
| ### Feat | ||
|
|
||
| - add new output | ||
|
|
||
| ### Fix | ||
|
|
||
| - output glitch | ||
|
|
||
| ## 0.1.0 (1970-01-01) |
Uh oh!
There was an error while loading. Please reload this page.