Skip to content

Commit 3449f6d

Browse files
fix(changelog): allow --no-incremental to override changelog_incremental config
The "Bump version" workflow's release-notes step runs `cz changelog --dry-run "${NEW_VERSION}"`, passing the new version as a positional rev_range. Since pyproject.toml sets `changelog_incremental = true` (#2074), this combination now always raises "--incremental cannot be combined with a rev_range", failing every release. There was previously no way to override a config-enabled `changelog_incremental` back to false from the CLI, since `--incremental` was a plain store_true flag defaulting to False. - Change `--incremental` to use argparse.BooleanOptionalAction (default None), adding a `--no-incremental` flag. - CLI flag now takes precedence over the `changelog_incremental` config setting; falls back to config only when neither flag is passed. Note: `.github/workflows/bumpversion.yml` still needs to be updated to pass `--no-incremental` in its release-notes step, but that change requires the `workflow` OAuth scope and is left for a follow-up/maintainer to apply. `cz bump`'s internal changelog call already hardcodes incremental=True, so it is unaffected by this change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4967717 commit 3449f6d

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

commitizen/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,13 @@ def __call__(
413413
},
414414
{
415415
"name": "--incremental",
416-
"action": "store_true",
417-
"default": False,
416+
"action": argparse.BooleanOptionalAction,
417+
"default": None,
418418
"help": (
419419
"Generate changelog from the last created version, "
420-
"useful if the changelog has been manually modified."
420+
"useful if the changelog has been manually modified. "
421+
"Use `--no-incremental` to override a `changelog_incremental` "
422+
"setting enabled in the configuration."
421423
),
422424
},
423425
{

commitizen/commands/changelog.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ChangelogArgs(TypedDict, total=False):
3232
current_version: str
3333
dry_run: bool
3434
file_name: str | None
35-
incremental: bool
35+
incremental: bool | None
3636
merge_prerelease: bool
3737
rev_range: str
3838
start_rev: str
@@ -78,9 +78,16 @@ def __init__(self, config: BaseConfig, arguments: ChangelogArgs) -> None:
7878

7979
self.changelog_format = get_changelog_format(self.config, self.file_name)
8080

81-
self.incremental = bool(
82-
arguments.get("incremental")
83-
or self.config.settings.get("changelog_incremental")
81+
# `--incremental`/`--no-incremental` on the CLI always takes precedence over
82+
# the `changelog_incremental` setting. When neither flag is passed, the
83+
# argument is `None` and we fall back to the config value. This lets a
84+
# one-off invocation (e.g. `cz changelog <rev_range>`) opt out of an
85+
# incremental default enabled in the configuration.
86+
incremental_arg = arguments.get("incremental")
87+
self.incremental = (
88+
incremental_arg
89+
if incremental_arg is not None
90+
else bool(self.config.settings.get("changelog_incremental"))
8491
)
8592
self.dry_run = bool(arguments.get("dry_run"))
8693

0 commit comments

Comments
 (0)