@@ -1494,6 +1494,46 @@ def test_changelog_config_flag_merge_prerelease_only_prerelease_present(
14941494 file_regression .check (out , extension = ".md" )
14951495
14961496
1497+ @pytest .mark .usefixtures ("tmp_commitizen_project" )
1498+ @pytest .mark .freeze_time ("2025-01-01" )
1499+ def test_changelog_merge_prerelease_preserves_header (
1500+ mocker : MockFixture ,
1501+ util : UtilFixture ,
1502+ changelog_path : Path ,
1503+ config_path : Path ,
1504+ file_regression : FileRegressionFixture ,
1505+ ):
1506+ """Test that merge_prerelease preserves existing changelog header."""
1507+ with config_path .open ("a" ) as f :
1508+ f .write ("changelog_merge_prerelease = true\n " )
1509+ f .write ("update_changelog_on_bump = true\n " )
1510+ f .write ("annotated_tag = true\n " )
1511+
1512+ # Create initial version with changelog that has a header
1513+ util .create_file_and_commit ("irrelevant commit" )
1514+ mocker .patch ("commitizen.git.GitTag.date" , "1970-01-01" )
1515+ git .tag ("0.1.0" )
1516+
1517+ # Create a changelog with a header manually
1518+ changelog_path .write_text (
1519+ "# Changelog\n \n All notable changes to this project will be documented here.\n \n ## 0.1.0 (1970-01-01)\n "
1520+ )
1521+
1522+ util .create_file_and_commit ("feat: add new output" )
1523+ util .create_file_and_commit ("fix: output glitch" )
1524+ util .run_cli ("bump" , "--prerelease" , "alpha" , "--yes" )
1525+
1526+ util .run_cli ("bump" , "--changelog" )
1527+
1528+ with changelog_path .open () as f :
1529+ out = f .read ()
1530+
1531+ # The header should be preserved
1532+ assert out .startswith ("# Changelog\n " )
1533+ assert "All notable changes to this project will be documented here." in out
1534+ file_regression .check (out , extension = ".md" )
1535+
1536+
14971537@pytest .mark .usefixtures ("tmp_commitizen_project" )
14981538def test_bump_deprecate_files_only (util : UtilFixture ):
14991539 util .create_file_and_commit ("feat: new file" )
0 commit comments