Skip to content

Commit ad35515

Browse files
feat(bump): add --version-files-only and deprecate --files-only (#1802)
Co-authored-by: abhishek <abhishekbansal8948@gmail.com>
1 parent 107680d commit ad35515

9 files changed

+70
-31
lines changed

commitizen/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,12 @@ def __call__(
210210
{
211211
"name": "--files-only", # TODO: rename to --version-files-only
212212
"action": "store_true",
213-
"help": "Bump version in the `version_files` specified in the configuration file only.",
213+
"help": "Bump version in the `version_files` specified in the configuration file only(deprecated; use --version-files-only instead).",
214+
},
215+
{
216+
"name": "--version-files-only",
217+
"action": "store_true",
218+
"help": "Bump version in the files from the config",
214219
},
215220
{
216221
"name": "--local-version",

commitizen/commands/bump.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class BumpArgs(Settings, total=False):
4949
dry_run: bool
5050
file_name: str
5151
files_only: bool | None
52+
version_files_only: bool | None
5253
get_next: bool # TODO: maybe rename to `next_version_to_stdout`
5354
git_output_to_stderr: bool
5455
increment_mode: str
@@ -365,7 +366,14 @@ def __call__(self) -> None:
365366
changelog_file_name=changelog_file_name,
366367
)
367368

368-
if self.arguments["files_only"]:
369+
if self.arguments.get("files_only"):
370+
warnings.warn(
371+
"--files-only is deprecated and will be removed in v5. Use --version-files-only instead.",
372+
DeprecationWarning,
373+
)
374+
raise ExpectedExit()
375+
376+
if self.arguments.get("version_files_only"):
369377
raise ExpectedExit()
370378

371379
# FIXME: check if any changes have been staged

docs/commands/bump.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ Commitizen supports the [PEP 440][pep440] version format, which includes several
122122

123123
![cz bump --help](../images/cli_help/cz_bump___help.svg)
124124

125-
### `--files-only`
125+
### `--version-files-only`
126126

127127
Bumps the version in the files defined in [`version_files`][version_files] without creating a commit and tag on the git repository.
128128

129129
```bash
130-
cz bump --files-only
130+
cz bump --version-files-only
131131
```
132132

133133
### `--changelog`

tests/commands/test_bump_command.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,8 @@ def test_bump_files_only(tmp_commitizen_project, util: UtilFixture):
418418

419419
util.create_file_and_commit("feat: another new feature")
420420
with pytest.raises(ExpectedExit):
421-
util.run_cli("bump", "--yes", "--files-only")
421+
util.run_cli("bump", "--yes", "--version-files-only")
422+
422423
assert git.tag_exist("0.3.0") is False
423424

424425
with open(tmp_version_file, encoding="utf-8") as f:
@@ -1204,7 +1205,7 @@ def test_bump_changelog_contains_increment_only(
12041205
# it should only include v3 changes
12051206
util.create_file_and_commit("feat(next)!: next version")
12061207
with pytest.raises(ExpectedExit):
1207-
util.run_cli("bump", "--yes", "--files-only", "--changelog-to-stdout")
1208+
util.run_cli("bump", "--yes", "--version-files-only", "--changelog-to-stdout")
12081209
out, _ = capsys.readouterr()
12091210

12101211
assert "3.0.0" in out
@@ -1492,3 +1493,13 @@ def test_changelog_config_flag_merge_prerelease_only_prerelease_present(
14921493
out = f.read()
14931494

14941495
file_regression.check(out, extension=".md")
1496+
1497+
1498+
@pytest.mark.usefixtures("tmp_commitizen_project")
1499+
def test_bump_deprecate_files_only(util: UtilFixture):
1500+
util.create_file_and_commit("feat: new file")
1501+
with (
1502+
pytest.warns(DeprecationWarning, match=r".*--files-only.*deprecated"),
1503+
pytest.raises(ExpectedExit),
1504+
):
1505+
util.run_cli("bump", "--yes", "--files-only")

tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_bump_.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
2-
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
3-
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
4-
[--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
1+
usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only]
2+
[--local-version] [--changelog] [--no-verify] [--yes]
3+
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
4+
[--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE]
5+
[--increment {MAJOR,MINOR,PATCH}]
56
[--increment-mode {linear,exact}] [--check-consistency]
67
[--annotated-tag]
78
[--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign]
@@ -24,7 +25,9 @@ options:
2425
--dry-run Perform a dry run, without committing or modifying
2526
files.
2627
--files-only Bump version in the `version_files` specified in the
27-
configuration file only.
28+
configuration file only(deprecated; use --version-
29+
files-only instead).
30+
--version-files-only Bump version in the files from the config
2831
--local-version Bump version only the local version portion (ignoring
2932
the public version).
3033
--changelog, -ch Generate the changelog for the latest version.

tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_bump_.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
2-
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
3-
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
4-
[--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
1+
usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only]
2+
[--local-version] [--changelog] [--no-verify] [--yes]
3+
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
4+
[--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE]
5+
[--increment {MAJOR,MINOR,PATCH}]
56
[--increment-mode {linear,exact}] [--check-consistency]
67
[--annotated-tag]
78
[--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign]
@@ -24,7 +25,9 @@ options:
2425
--dry-run Perform a dry run, without committing or modifying
2526
files.
2627
--files-only Bump version in the `version_files` specified in the
27-
configuration file only.
28+
configuration file only(deprecated; use --version-
29+
files-only instead).
30+
--version-files-only Bump version in the files from the config
2831
--local-version Bump version only the local version portion (ignoring
2932
the public version).
3033
--changelog, -ch Generate the changelog for the latest version.

tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_bump_.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
2-
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
3-
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
4-
[--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
1+
usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only]
2+
[--local-version] [--changelog] [--no-verify] [--yes]
3+
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
4+
[--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE]
5+
[--increment {MAJOR,MINOR,PATCH}]
56
[--increment-mode {linear,exact}] [--check-consistency]
67
[--annotated-tag]
78
[--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign]
@@ -24,7 +25,9 @@ options:
2425
--dry-run Perform a dry run, without committing or modifying
2526
files.
2627
--files-only Bump version in the `version_files` specified in the
27-
configuration file only.
28+
configuration file only(deprecated; use --version-
29+
files-only instead).
30+
--version-files-only Bump version in the files from the config
2831
--local-version Bump version only the local version portion (ignoring
2932
the public version).
3033
--changelog, -ch Generate the changelog for the latest version.

tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_bump_.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
2-
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
3-
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
4-
[--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
1+
usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only]
2+
[--local-version] [--changelog] [--no-verify] [--yes]
3+
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
4+
[--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE]
5+
[--increment {MAJOR,MINOR,PATCH}]
56
[--increment-mode {linear,exact}] [--check-consistency]
67
[--annotated-tag]
78
[--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign]
@@ -24,7 +25,9 @@ options:
2425
--dry-run Perform a dry run, without committing or modifying
2526
files.
2627
--files-only Bump version in the `version_files` specified in the
27-
configuration file only.
28+
configuration file only(deprecated; use --version-
29+
files-only instead).
30+
--version-files-only Bump version in the files from the config
2831
--local-version Bump version only the local version portion (ignoring
2932
the public version).
3033
--changelog, -ch Generate the changelog for the latest version.

tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_bump_.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
2-
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
3-
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
4-
[--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}]
1+
usage: cz bump [-h] [--dry-run] [--files-only] [--version-files-only]
2+
[--local-version] [--changelog] [--no-verify] [--yes]
3+
[--tag-format TAG_FORMAT] [--bump-message BUMP_MESSAGE]
4+
[--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE]
5+
[--increment {MAJOR,MINOR,PATCH}]
56
[--increment-mode {linear,exact}] [--check-consistency]
67
[--annotated-tag]
78
[--annotated-tag-message ANNOTATED_TAG_MESSAGE] [--gpg-sign]
@@ -24,7 +25,9 @@ options:
2425
--dry-run Perform a dry run, without committing or modifying
2526
files.
2627
--files-only Bump version in the `version_files` specified in the
27-
configuration file only.
28+
configuration file only(deprecated; use --version-
29+
files-only instead).
30+
--version-files-only Bump version in the files from the config
2831
--local-version Bump version only the local version portion (ignoring
2932
the public version).
3033
--changelog, -ch Generate the changelog for the latest version.

0 commit comments

Comments
 (0)