From b5e7cdb309c07d8258f44dadd01b1f2d64d895d2 Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 19 Nov 2025 20:57:27 +0530 Subject: [PATCH] feat(bump): add --version-files-only and deprecate --files-only --- commitizen/cli.py | 5 +++++ commitizen/commands/bump.py | 10 +++++++++- docs/commands/bump.md | 4 ++-- tests/commands/test_bump_command.py | 12 ++++++++++-- ...scription_when_use_help_option_py_3_10_bump_.txt | 13 ++++++++----- ...scription_when_use_help_option_py_3_11_bump_.txt | 13 ++++++++----- ...scription_when_use_help_option_py_3_12_bump_.txt | 13 ++++++++----- ...scription_when_use_help_option_py_3_13_bump_.txt | 13 ++++++++----- ...scription_when_use_help_option_py_3_14_bump_.txt | 13 ++++++++----- 9 files changed, 66 insertions(+), 30 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 364bc93f8..852caf4d2 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -208,6 +208,11 @@ def __call__( { "name": "--files-only", "action": "store_true", + "help": "Bump version in config files (deprecated; use --version-files-only instead).", + }, + { + "name": "--version-files-only", + "action": "store_true", "help": "bump version in the files from the config", }, { diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index f6637b5c7..b51a3f8ab 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -49,6 +49,7 @@ class BumpArgs(Settings, total=False): dry_run: bool file_name: str files_only: bool | None + version_files_only: bool | None get_next: bool # TODO: maybe rename to `next_version_to_stdout` git_output_to_stderr: bool increment_mode: str @@ -366,7 +367,14 @@ def __call__(self) -> None: else None, ) - if self.arguments["files_only"]: + if self.arguments.get("files_only"): + warnings.warn( + "--files-only is deprecated and will be removed in v5. Use --version-files-only instead.", + DeprecationWarning, + ) + raise ExpectedExit() + + if self.arguments.get("version_files_only"): raise ExpectedExit() # FIXME: check if any changes have been staged diff --git a/docs/commands/bump.md b/docs/commands/bump.md index e7a7c0403..f5c101f7e 100644 --- a/docs/commands/bump.md +++ b/docs/commands/bump.md @@ -109,12 +109,12 @@ Commitizen supports the [PEP 440][pep440] version format, which includes several ![cz bump --help](../images/cli_help/cz_bump___help.svg) -### `--files-only` +### `--version-files-only` Bumps the version in the files defined in [`version_files`][version_files] without creating a commit and tag on the git repository. ```bash -cz bump --files-only +cz bump --version-files-only ``` ### `--changelog` diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index d79a76b5a..a3cd81a14 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -470,7 +470,7 @@ def test_bump_files_only(tmp_commitizen_project, util: UtilFixture): util.create_file_and_commit("feat: another new feature") with pytest.raises(ExpectedExit): - util.run_cli("bump", "--yes", "--files-only") + util.run_cli("bump", "--yes", "--version-files-only") tag_exists = git.tag_exist("0.3.0") assert tag_exists is False @@ -1267,7 +1267,7 @@ def test_bump_changelog_contains_increment_only( # it should only include v3 changes util.create_file_and_commit("feat(next)!: next version") with pytest.raises(ExpectedExit): - util.run_cli("bump", "--yes", "--files-only", "--changelog-to-stdout") + util.run_cli("bump", "--yes", "--version-files-only", "--changelog-to-stdout") out, _ = capsys.readouterr() assert "3.0.0" in out @@ -1557,3 +1557,11 @@ def test_changelog_config_flag_merge_prerelease_only_prerelease_present( out = f.read() file_regression.check(out, extension=".md") + + +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_bump_deprecate_files_only(util: UtilFixture): + util.create_file_and_commit("feat: new file") + with pytest.warns(DeprecationWarning): + with pytest.raises(ExpectedExit): + util.run_cli("bump", "--yes", "--files-only") diff --git a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_bump_.txt b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_bump_.txt index ad0a69327..7d3bc61bf 100644 --- a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_bump_.txt +++ b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_bump_.txt @@ -1,7 +1,8 @@ -usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] - [--no-verify] [--yes] [--tag-format TAG_FORMAT] - [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] - [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}] +usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only] + [--local-version] [--changelog] [--no-verify] [--yes] + [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] + [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] + [--increment {MAJOR,MINOR,PATCH}] [--increment-mode {linear,exact}] [--check-consistency] [--annotated-tag] [--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign] @@ -22,7 +23,9 @@ positional arguments: options: -h, --help show this help message and exit --dry-run show output to stdout, no commit, no modified files - --files-only bump version in the files from the config + --files-only Bump version in config files (deprecated; use + --version-files-only instead). + --version-files-only bump version in the files from the config --local-version bump only the local version portion --changelog, -ch generate the changelog for the newest version --no-verify this option bypasses the pre-commit and commit-msg diff --git a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_bump_.txt b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_bump_.txt index ad0a69327..7d3bc61bf 100644 --- a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_bump_.txt +++ b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_bump_.txt @@ -1,7 +1,8 @@ -usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] - [--no-verify] [--yes] [--tag-format TAG_FORMAT] - [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] - [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}] +usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only] + [--local-version] [--changelog] [--no-verify] [--yes] + [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] + [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] + [--increment {MAJOR,MINOR,PATCH}] [--increment-mode {linear,exact}] [--check-consistency] [--annotated-tag] [--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign] @@ -22,7 +23,9 @@ positional arguments: options: -h, --help show this help message and exit --dry-run show output to stdout, no commit, no modified files - --files-only bump version in the files from the config + --files-only Bump version in config files (deprecated; use + --version-files-only instead). + --version-files-only bump version in the files from the config --local-version bump only the local version portion --changelog, -ch generate the changelog for the newest version --no-verify this option bypasses the pre-commit and commit-msg diff --git a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_bump_.txt b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_bump_.txt index ad0a69327..7d3bc61bf 100644 --- a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_bump_.txt +++ b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_bump_.txt @@ -1,7 +1,8 @@ -usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] - [--no-verify] [--yes] [--tag-format TAG_FORMAT] - [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] - [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}] +usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only] + [--local-version] [--changelog] [--no-verify] [--yes] + [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] + [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] + [--increment {MAJOR,MINOR,PATCH}] [--increment-mode {linear,exact}] [--check-consistency] [--annotated-tag] [--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign] @@ -22,7 +23,9 @@ positional arguments: options: -h, --help show this help message and exit --dry-run show output to stdout, no commit, no modified files - --files-only bump version in the files from the config + --files-only Bump version in config files (deprecated; use + --version-files-only instead). + --version-files-only bump version in the files from the config --local-version bump only the local version portion --changelog, -ch generate the changelog for the newest version --no-verify this option bypasses the pre-commit and commit-msg diff --git a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_bump_.txt b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_bump_.txt index 4cf8e6c91..86eae7d43 100644 --- a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_bump_.txt +++ b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_bump_.txt @@ -1,7 +1,8 @@ -usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] - [--no-verify] [--yes] [--tag-format TAG_FORMAT] - [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] - [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}] +usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only] + [--local-version] [--changelog] [--no-verify] [--yes] + [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] + [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] + [--increment {MAJOR,MINOR,PATCH}] [--increment-mode {linear,exact}] [--check-consistency] [--annotated-tag] [--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign] @@ -22,7 +23,9 @@ positional arguments: options: -h, --help show this help message and exit --dry-run show output to stdout, no commit, no modified files - --files-only bump version in the files from the config + --files-only Bump version in config files (deprecated; use + --version-files-only instead). + --version-files-only bump version in the files from the config --local-version bump only the local version portion --changelog, -ch generate the changelog for the newest version --no-verify this option bypasses the pre-commit and commit-msg diff --git a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_bump_.txt b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_bump_.txt index 4cf8e6c91..86eae7d43 100644 --- a/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_bump_.txt +++ b/tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_bump_.txt @@ -1,7 +1,8 @@ -usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] - [--no-verify] [--yes] [--tag-format TAG_FORMAT] - [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] - [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}] +usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only] + [--local-version] [--changelog] [--no-verify] [--yes] + [--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE] + [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] + [--increment {MAJOR,MINOR,PATCH}] [--increment-mode {linear,exact}] [--check-consistency] [--annotated-tag] [--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign] @@ -22,7 +23,9 @@ positional arguments: options: -h, --help show this help message and exit --dry-run show output to stdout, no commit, no modified files - --files-only bump version in the files from the config + --files-only Bump version in config files (deprecated; use + --version-files-only instead). + --version-files-only bump version in the files from the config --local-version bump only the local version portion --changelog, -ch generate the changelog for the newest version --no-verify this option bypasses the pre-commit and commit-msg