Skip to content

Commit d7cabb5

Browse files
committed
refactor(bump): rename variables and remove unreachable logic
1 parent 0695a2f commit d7cabb5

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
@@ -94,7 +93,6 @@ def __init__(self, config: BaseConfig, arguments: BumpArgs) -> None:
9493
)
9594
self.cz = factory.committer_factory(self.config)
9695
self.changelog_flag = arguments["changelog"]
97-
self.changelog_config = self.config.settings.get("update_changelog_on_bump")
9896
self.changelog_to_stdout = arguments["changelog_to_stdout"]
9997
self.git_output_to_stderr = arguments["git_output_to_stderr"]
10098
self.no_verify = arguments["no_verify"]
@@ -169,7 +167,9 @@ def __call__(self) -> None:
169167
is_local_version = self.arguments["local_version"]
170168
manual_version = self.arguments["manual_version"]
171169
build_metadata = self.arguments["build_metadata"]
172-
get_next = self.arguments["get_next"]
170+
next_version_to_stdout = self.arguments[
171+
"get_next"
172+
] # TODO: maybe rename to `next_version_to_stdout`
173173
allow_no_commit = self.arguments["allow_no_commit"]
174174
major_version_zero = self.arguments["major_version_zero"]
175175

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

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

216214
rules = TagRules.from_settings(cast(Settings, self.bump_settings))
217215
current_tag = rules.find_tag_for(git.get_tags(), current_version)
@@ -270,20 +268,18 @@ def __call__(self) -> None:
270268
)
271269

272270
new_tag_version = rules.normalize_tag(new_version)
273-
message = bump.create_commit_message(
274-
current_version, new_version, self.bump_settings["bump_message"]
275-
)
276-
277-
if get_next:
271+
if next_version_to_stdout:
278272
if increment is None and new_tag_version == current_tag_version:
279273
raise NoneIncrementExit(
280274
"[NO_COMMITS_TO_BUMP]\n"
281275
"The commits found are not eligible to be bumped"
282276
)
283-
284277
out.write(str(new_version))
285-
raise GetNextExit()
278+
raise DryRunExit()
286279

280+
message = bump.create_commit_message(
281+
current_version, new_version, self.bump_settings["bump_message"]
282+
)
287283
# Report found information
288284
information = f"{message}\ntag to create: {new_tag_version}\n"
289285
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)