Skip to content

Commit 5cc10ae

Browse files
committed
fix(bump): remove NotAllowed related to --get-next option, and other related refactoring
1 parent 939ee43 commit 5cc10ae

File tree

3 files changed

+22
-64
lines changed

3 files changed

+22
-64
lines changed

commitizen/commands/bump.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
BumpTagFailedError,
1717
DryRunExit,
1818
ExpectedExit,
19-
GetNextExit,
2019
InvalidManualVersion,
2120
NoCommitsFoundError,
2221
NoneIncrementExit,
@@ -47,7 +46,7 @@ class BumpArgs(Settings, total=False):
4746
dry_run: bool
4847
file_name: str
4948
files_only: bool | None
50-
get_next: bool
49+
get_next: bool # TODO: maybe rename to `next_version_to_stdout`
5150
git_output_to_stderr: bool
5251
increment_mode: str
5352
increment: Increment | None
@@ -95,7 +94,6 @@ def __init__(self, config: BaseConfig, arguments: BumpArgs) -> None:
9594
)
9695
self.cz = factory.committer_factory(self.config)
9796
self.changelog_flag = arguments["changelog"]
98-
self.changelog_config = self.config.settings.get("update_changelog_on_bump")
9997
self.changelog_to_stdout = arguments["changelog_to_stdout"]
10098
self.git_output_to_stderr = arguments["git_output_to_stderr"]
10199
self.no_verify = arguments["no_verify"]
@@ -170,7 +168,9 @@ def __call__(self) -> None:
170168
is_local_version = self.arguments["local_version"]
171169
manual_version = self.arguments["manual_version"]
172170
build_metadata = self.arguments["build_metadata"]
173-
get_next = self.arguments["get_next"]
171+
next_version_to_stdout = self.arguments[
172+
"get_next"
173+
] # TODO: maybe rename to `next_version_to_stdout`
174174
allow_no_commit = self.arguments["allow_no_commit"]
175175
major_version_zero = self.arguments["major_version_zero"]
176176

@@ -182,7 +182,6 @@ def __call__(self) -> None:
182182
(is_local_version, "--local-version"),
183183
(build_metadata, "--build-metadata"),
184184
(major_version_zero, "--major-version-zero"),
185-
(get_next, "--get-next"),
186185
):
187186
if val:
188187
raise NotAllowed(f"{option} cannot be combined with MANUAL_VERSION")
@@ -195,24 +194,23 @@ def __call__(self) -> None:
195194
if build_metadata and is_local_version:
196195
raise NotAllowed("--local-version cannot be combined with --build-metadata")
197196

198-
if get_next:
197+
if next_version_to_stdout:
199198
for value, option in (
200199
(self.changelog_flag, "--changelog"),
201200
(self.changelog_to_stdout, "--changelog-to-stdout"),
202201
):
203202
if value:
204-
raise NotAllowed(f"{option} cannot be combined with --get-next")
205-
206-
# --get-next is a special case, taking precedence over config for 'update_changelog_on_bump'
207-
self.changelog_config = False
208-
# Setting dry_run to prevent any unwanted changes to the repo or files
209-
self.dry_run = True
210-
else:
211-
# If user specified changelog_to_stdout, they probably want the
212-
# changelog to be generated as well, this is the most intuitive solution
213-
self.changelog_flag = any(
214-
(self.changelog_flag, self.changelog_to_stdout, self.changelog_config)
203+
warnings.warn(f"{option} has no effect when used with --get-next")
204+
205+
# If user specified changelog_to_stdout, they probably want the
206+
# changelog to be generated as well, this is the most intuitive solution
207+
self.changelog_flag = any(
208+
(
209+
self.changelog_flag,
210+
self.changelog_to_stdout,
211+
self.config.settings.get("update_changelog_on_bump"),
215212
)
213+
)
216214

217215
rules = TagRules.from_settings(cast(Settings, self.bump_settings))
218216
current_tag = rules.find_tag_for(git.get_tags(), current_version)
@@ -271,20 +269,18 @@ def __call__(self) -> None:
271269
)
272270

273271
new_tag_version = rules.normalize_tag(new_version)
274-
message = bump.create_commit_message(
275-
current_version, new_version, self.bump_settings["bump_message"]
276-
)
277-
278-
if get_next:
272+
if next_version_to_stdout:
279273
if increment is None and new_tag_version == current_tag_version:
280274
raise NoneIncrementExit(
281275
"[NO_COMMITS_TO_BUMP]\n"
282276
"The commits found are not eligible to be bumped"
283277
)
284-
285278
out.write(str(new_version))
286-
raise GetNextExit()
279+
raise DryRunExit()
287280

281+
message = bump.create_commit_message(
282+
current_version, new_version, self.bump_settings["bump_message"]
283+
)
288284
# Report found information
289285
information = f"{message}\ntag to create: {new_tag_version}\n"
290286
if increment:

commitizen/exceptions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ class DryRunExit(ExpectedExit):
7575
pass
7676

7777

78-
class GetNextExit(ExpectedExit):
79-
pass
80-
81-
8278
class NoneIncrementExit(CommitizenException):
8379
exit_code = ExitCode.NO_INCREMENT
8480

tests/commands/test_bump_command.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
DryRunExit,
2424
ExitCode,
2525
ExpectedExit,
26-
GetNextExit,
2726
InvalidManualVersion,
2827
NoCommitsFoundError,
2928
NoneIncrementExit,
@@ -1456,7 +1455,7 @@ def test_bump_get_next(mocker: MockFixture, capsys):
14561455

14571456
testargs = ["cz", "bump", "--yes", "--get-next"]
14581457
mocker.patch.object(sys, "argv", testargs)
1459-
with pytest.raises(GetNextExit):
1458+
with pytest.raises(DryRunExit):
14601459
cli.main()
14611460

14621461
out, _ = capsys.readouterr()
@@ -1476,7 +1475,7 @@ def test_bump_get_next_update_changelog_on_bump(
14761475

14771476
testargs = ["cz", "bump", "--yes", "--get-next"]
14781477
mocker.patch.object(sys, "argv", testargs)
1479-
with pytest.raises(GetNextExit):
1478+
with pytest.raises(DryRunExit):
14801479
cli.main()
14811480

14821481
out, _ = capsys.readouterr()
@@ -1486,39 +1485,6 @@ def test_bump_get_next_update_changelog_on_bump(
14861485
assert tag_exists is False
14871486

14881487

1489-
@pytest.mark.usefixtures("tmp_commitizen_project")
1490-
def test_bump_get_next__changelog_is_not_allowed(mocker: MockFixture):
1491-
create_file_and_commit("feat: new file")
1492-
1493-
testargs = ["cz", "bump", "--yes", "--get-next", "--changelog"]
1494-
mocker.patch.object(sys, "argv", testargs)
1495-
1496-
with pytest.raises(NotAllowed):
1497-
cli.main()
1498-
1499-
1500-
@pytest.mark.usefixtures("tmp_commitizen_project")
1501-
def test_bump_get_next__changelog_to_stdout_is_not_allowed(mocker: MockFixture):
1502-
create_file_and_commit("feat: new file")
1503-
1504-
testargs = ["cz", "bump", "--yes", "--get-next", "--changelog-to-stdout"]
1505-
mocker.patch.object(sys, "argv", testargs)
1506-
1507-
with pytest.raises(NotAllowed):
1508-
cli.main()
1509-
1510-
1511-
@pytest.mark.usefixtures("tmp_commitizen_project")
1512-
def test_bump_get_next__manual_version_is_not_allowed(mocker: MockFixture):
1513-
create_file_and_commit("feat: new file")
1514-
1515-
testargs = ["cz", "bump", "--yes", "--get-next", "0.2.1"]
1516-
mocker.patch.object(sys, "argv", testargs)
1517-
1518-
with pytest.raises(NotAllowed):
1519-
cli.main()
1520-
1521-
15221488
@pytest.mark.usefixtures("tmp_commitizen_project")
15231489
def test_bump_get_next__no_eligible_commits_raises(mocker: MockFixture):
15241490
create_file_and_commit("chore: new commit")

0 commit comments

Comments
 (0)