fix(commands/bump): prevent using incremental changelog when it is set to false in config by josix · Pull Request #996 · commitizen-tools/commitizen · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion commitizen/commands/bump.py
8 changes: 6 additions & 2 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Settings(TypedDict, total=False):
change_type_map: dict[str, str]
changelog_file: str
changelog_format: str | None
changelog_incremental: bool
changelog_incremental: bool | None
changelog_merge_prerelease: bool
changelog_start_rev: str | None
customize: CzSettings
Expand Down Expand Up @@ -100,7 +100,11 @@ class Settings(TypedDict, total=False):
],
"changelog_file": "CHANGELOG.md",
"changelog_format": None, # default guessed from changelog_file
"changelog_incremental": False,
# None serves as a sentinel for "not configured by user" (distinct from False = explicitly disabled).
# During `cz bump`, when unset (None), defaults to True (incremental changelog).
# TODO: consider introducing sentinel value for "not configured by user" instead of overloading None,
# to avoid confusion with False.
"changelog_incremental": None,
"changelog_start_rev": None,
"changelog_merge_prerelease": False,
"update_changelog_on_bump": False,
Expand Down
86 changes: 86 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,3 +1502,89 @@ def test_bump_deprecate_files_only(util: UtilFixture):
pytest.raises(ExpectedExit),
):
util.run_cli("bump", "--yes", "--files-only")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_changelog_incremental_default_not_set(
util: UtilFixture, changelog_path: Path, config_path: Path
):
with config_path.open("a", encoding="utf-8") as fp:
fp.write("update_changelog_on_bump = true\n")

Comment on lines +1507 to +1513
util.create_file_and_commit("feat(user): new user")
util.run_cli("bump", "--yes")
assert git.tag_exist("0.2.0") is True

with changelog_path.open(encoding="utf-8") as f:
content = f.read()
with changelog_path.open("w", encoding="utf-8") as f:
f.write(content.replace("- **user**: new user", "- **user**: new user\n\nMANUAL NOTE"))
util.create_file_and_commit("docs: add manual note to changelog")

util.create_file_and_commit("feat(admin): new admin")
util.run_cli("bump", "--yes")
assert git.tag_exist("0.3.0") is True

with changelog_path.open(encoding="utf-8") as f:
out = f.read()
assert "0.3.0" in out
assert "0.2.0" in out
assert "MANUAL NOTE" in out


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_changelog_incremental_set_true(
util: UtilFixture, changelog_path: Path, config_path: Path
):
with config_path.open("a", encoding="utf-8") as fp:
fp.write("update_changelog_on_bump = true\n")
fp.write("changelog_incremental = true\n")

util.create_file_and_commit("feat(user): new user")
util.run_cli("bump", "--yes")
assert git.tag_exist("0.2.0") is True

with changelog_path.open(encoding="utf-8") as f:
content = f.read()
with changelog_path.open("w", encoding="utf-8") as f:
f.write(content.replace("- **user**: new user", "- **user**: new user\n\nMANUAL NOTE"))
util.create_file_and_commit("docs: add manual note to changelog")

util.create_file_and_commit("feat(admin): new admin")
util.run_cli("bump", "--yes")
assert git.tag_exist("0.3.0") is True

with changelog_path.open(encoding="utf-8") as f:
out = f.read()
assert "0.3.0" in out
assert "0.2.0" in out
assert "MANUAL NOTE" in out


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_changelog_incremental_set_false(
util: UtilFixture, changelog_path: Path, config_path: Path
):
with config_path.open("a", encoding="utf-8") as fp:
fp.write("update_changelog_on_bump = true\n")
fp.write("changelog_incremental = false\n")

util.create_file_and_commit("feat(user): new user")
util.run_cli("bump", "--yes")
assert git.tag_exist("0.2.0") is True

with changelog_path.open(encoding="utf-8") as f:
content = f.read()
with changelog_path.open("w", encoding="utf-8") as f:
f.write(content.replace("- **user**: new user", "- **user**: new user\n\nMANUAL NOTE"))
util.create_file_and_commit("docs: add manual note to changelog")

util.create_file_and_commit("feat(admin): new admin")
util.run_cli("bump", "--yes")
assert git.tag_exist("0.3.0") is True

with changelog_path.open(encoding="utf-8") as f:
out = f.read()
assert "0.3.0" in out
assert "0.2.0" in out
assert "MANUAL NOTE" not in out
4 changes: 2 additions & 2 deletions tests/test_conf.py