Skip to content

Commit 5c79488

Browse files
committed
test: add tests for changelog incremental behavior during bump
1 parent 0b31a73 commit 5c79488

3 files changed

Lines changed: 93 additions & 2 deletions

File tree

commitizen/commands/bump.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ def __call__(self) -> None:
310310
changelog_file_name = None
311311
dry_run = self.arguments["dry_run"]
312312
if self.changelog_flag:
313-
# "changelog_incremental" defaults to None in settings, so we can't
314-
# rely on .get(key, True); default to True for bump only when unset.
313+
# DEFAULT_SETTINGS provides changelog_incremental=None, so .get("changelog_incremental", True)
314+
# would never fall through to the True default. None means "not configured" vs False meaning
315+
# "explicitly disabled". During bump, we default to True (incremental) when not configured.
315316
incremental_setting = self.config.settings.get("changelog_incremental")
316317
changelog_args = {
317318
"unreleased_version": new_tag_version,

commitizen/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class Settings(TypedDict, total=False):
100100
],
101101
"changelog_file": "CHANGELOG.md",
102102
"changelog_format": None, # default guessed from changelog_file
103+
# None serves as a sentinel for "not configured by user" (distinct from False = explicitly disabled).
104+
# During `cz bump`, when unset (None), defaults to True (incremental changelog).
105+
# TODO: consider introducing sentinel value for "not configured by user" instead of overloading None,
106+
# to avoid confusion with False.
103107
"changelog_incremental": None,
104108
"changelog_start_rev": None,
105109
"changelog_merge_prerelease": False,

tests/commands/test_bump_command.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,3 +1502,89 @@ def test_bump_deprecate_files_only(util: UtilFixture):
15021502
pytest.raises(ExpectedExit),
15031503
):
15041504
util.run_cli("bump", "--yes", "--files-only")
1505+
1506+
1507+
@pytest.mark.usefixtures("tmp_commitizen_project")
1508+
def test_bump_changelog_incremental_default_not_set(
1509+
util: UtilFixture, changelog_path: Path, config_path: Path
1510+
):
1511+
with config_path.open("a", encoding="utf-8") as fp:
1512+
fp.write("update_changelog_on_bump = true\n")
1513+
1514+
util.create_file_and_commit("feat(user): new user")
1515+
util.run_cli("bump", "--yes")
1516+
assert git.tag_exist("0.2.0") is True
1517+
1518+
with changelog_path.open(encoding="utf-8") as f:
1519+
content = f.read()
1520+
with changelog_path.open("w", encoding="utf-8") as f:
1521+
f.write(content.replace("- **user**: new user", "- **user**: new user\n\nMANUAL NOTE"))
1522+
util.create_file_and_commit("docs: add manual note to changelog")
1523+
1524+
util.create_file_and_commit("feat(admin): new admin")
1525+
util.run_cli("bump", "--yes")
1526+
assert git.tag_exist("0.3.0") is True
1527+
1528+
with changelog_path.open(encoding="utf-8") as f:
1529+
out = f.read()
1530+
assert "0.3.0" in out
1531+
assert "0.2.0" in out
1532+
assert "MANUAL NOTE" in out
1533+
1534+
1535+
@pytest.mark.usefixtures("tmp_commitizen_project")
1536+
def test_bump_changelog_incremental_set_true(
1537+
util: UtilFixture, changelog_path: Path, config_path: Path
1538+
):
1539+
with config_path.open("a", encoding="utf-8") as fp:
1540+
fp.write("update_changelog_on_bump = true\n")
1541+
fp.write("changelog_incremental = true\n")
1542+
1543+
util.create_file_and_commit("feat(user): new user")
1544+
util.run_cli("bump", "--yes")
1545+
assert git.tag_exist("0.2.0") is True
1546+
1547+
with changelog_path.open(encoding="utf-8") as f:
1548+
content = f.read()
1549+
with changelog_path.open("w", encoding="utf-8") as f:
1550+
f.write(content.replace("- **user**: new user", "- **user**: new user\n\nMANUAL NOTE"))
1551+
util.create_file_and_commit("docs: add manual note to changelog")
1552+
1553+
util.create_file_and_commit("feat(admin): new admin")
1554+
util.run_cli("bump", "--yes")
1555+
assert git.tag_exist("0.3.0") is True
1556+
1557+
with changelog_path.open(encoding="utf-8") as f:
1558+
out = f.read()
1559+
assert "0.3.0" in out
1560+
assert "0.2.0" in out
1561+
assert "MANUAL NOTE" in out
1562+
1563+
1564+
@pytest.mark.usefixtures("tmp_commitizen_project")
1565+
def test_bump_changelog_incremental_set_false(
1566+
util: UtilFixture, changelog_path: Path, config_path: Path
1567+
):
1568+
with config_path.open("a", encoding="utf-8") as fp:
1569+
fp.write("update_changelog_on_bump = true\n")
1570+
fp.write("changelog_incremental = false\n")
1571+
1572+
util.create_file_and_commit("feat(user): new user")
1573+
util.run_cli("bump", "--yes")
1574+
assert git.tag_exist("0.2.0") is True
1575+
1576+
with changelog_path.open(encoding="utf-8") as f:
1577+
content = f.read()
1578+
with changelog_path.open("w", encoding="utf-8") as f:
1579+
f.write(content.replace("- **user**: new user", "- **user**: new user\n\nMANUAL NOTE"))
1580+
util.create_file_and_commit("docs: add manual note to changelog")
1581+
1582+
util.create_file_and_commit("feat(admin): new admin")
1583+
util.run_cli("bump", "--yes")
1584+
assert git.tag_exist("0.3.0") is True
1585+
1586+
with changelog_path.open(encoding="utf-8") as f:
1587+
out = f.read()
1588+
assert "0.3.0" in out
1589+
assert "0.2.0" in out
1590+
assert "MANUAL NOTE" not in out

0 commit comments

Comments
 (0)