Skip to content

Commit f039a5e

Browse files
Add a failing test
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
1 parent a6db54c commit f039a5e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tests/commands/test_bump_command.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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\nAll 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")
14981538
def test_bump_deprecate_files_only(util: UtilFixture):
14991539
util.create_file_and_commit("feat: new file")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented here.
4+
5+
## 0.2.0 (2025-01-01)
6+
7+
### Feat
8+
9+
- add new output
10+
11+
### Fix
12+
13+
- output glitch
14+
15+
## 0.1.0 (1970-01-01)

0 commit comments

Comments
 (0)