fix(commands/bump): prevent using incremental changelog when it is set to false in config#996
Conversation
661a140 to
d4894e5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #996 +/- ##
=======================================
Coverage 97.99% 97.99%
=======================================
Files 60 60
Lines 2691 2693 +2
=======================================
+ Hits 2637 2639 +2
Misses 54 54 ☔ View full report in Codecov by Sentry. |
d4894e5 to
45b9352
Compare
|
Just opening the debate: wouldn't it be easier and more consistent to fix/align the default By adding a fourth settings source of trust (defaults, user settings, cli flags and now mutated settings, fifth if you add the fact that plugins can override some settings), I feel that we are fixing a symptom but making the problem more complex. |
Yeah, I think that would be a better way to address the issue if possible. The implementation would be easier and also could prevent overriding the behaviors from multiple sources when running the |
Could you make a proposal for this? It sounds interesting, would be nice if we can simplify the settings |
|
I'm a bit confused here. I thought we could solve it by reading the value from config? |
I think there are total three combinations of configurations here:
The 1st & 3rd cases would cause ambiguity when we're reading the value from |
I thought the one from the config should overwrite the default. Or did I miss anything? |
|
Hello, Do you guys have any news on this fix ? |
|
@josix what is the status of this PR? Thanks! |
|
Oh I missed this comment, let me pick this up |
|
Thanks! |
d439c38 to
aef2004
Compare
c2df766 to
5ecaa15
Compare
7162151 to
9c8f89a
Compare
| "incremental": incremental_setting | ||
| if incremental_setting is not None | ||
| else True, |
There was a problem hiding this comment.
This probably also works and is less confusing
| "incremental": incremental_setting | |
| if incremental_setting is not None | |
| else True, | |
| "incremental": self.config.settings.get("changelog_incremental", True), |
There was a problem hiding this comment.
yeah, thanks for pointing it out.
There was a problem hiding this comment.
weird, seems that it will let tests fail, let me investigate it.
There was a problem hiding this comment.
Oh, I found the root cause, dict.get only returns the fallback when the key is missing, so .get(..., True) would return None (not True). The explicit check is required to default to incremental changelog generation while still honoring an explicit False.
There was a problem hiding this comment.
It does remind me that Airflow has an ARG_NOT_SET thing. not sure whether we should have similiar mechanism
There was a problem hiding this comment.
I think we'll also need more context in this comment. same as the value in default.py. This is probably the best we can do for the time being, but worth thinking of a abetter solution in the following major versions. also would be great if we have a unit test to cover it
0002ced to
181db46
Compare
181db46 to
0b31a73
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes cz bump --changelog / update_changelog_on_bump = true so that an explicit changelog_incremental = false in user config is respected (i.e., bump-generated changelog is non-incremental when configured).
Changes:
- Change the default
changelog_incrementalsetting toNoneas a sentinel meaning “not configured by user”. - Update
bumpto treatNoneas “unset” and default to incremental changelog generation during bump, while still honoring explicittrue/false. - Add bump command tests covering unset/true/false
changelog_incrementalbehavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
commitizen/defaults.py |
Makes changelog_incremental a tri-state setting (`bool |
commitizen/commands/bump.py |
Uses the tri-state value to default to incremental during bump only when the setting is unset. |
tests/test_conf.py |
Updates expected default settings to reflect changelog_incremental = None. |
tests/commands/test_bump_command.py |
Adds regression tests ensuring bump preserves/overwrites manual changelog edits depending on changelog_incremental. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @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") | ||
|
|
Fix #883
Description
Since the default behavior of
cz bump --changelogis to write incremental changelog, which is different from the default value ofchangelog_incremental, it is hard to know the value is set from user or the default setting, To address it, I created one more member inBaseConfigto record which property is defined from users so that we could distinguish the value is from default setting or users.Checklist
./scripts/formatand./scripts/testlocally to ensure this change passes linter check and testExpected behavior
cz bump --changelogshould work asfalsewhen user configurechangelog_incrementaltofalse.Steps to Test This Pull Request
Modify the CHANGELOG file

Configure
pyproject.tomlwithchangelog_incremental = falseRun
cz bump --changelogCheck the CHANGELOG, which the new added content should be replaced

Additional context
ditto.