Skip to content

Commit f9a0e2b

Browse files
chadrikwoile
authored andcommitted
fix(bump): change --exact-increment to --increment-mode
This provides some future proofing for implementing new version progression behaviors
1 parent c245b14 commit f9a0e2b

File tree

4 files changed

+51
-31
lines changed

4 files changed

+51
-31
lines changed

Diff for: commitizen/cli.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,16 @@ def __call__(
231231
"type": str.upper,
232232
},
233233
{
234-
"name": ["--exact-increment"],
235-
"action": "store_true",
234+
"name": ["--increment-mode"],
235+
"choices": ["linear", "exact"],
236+
"default": "linear",
236237
"help": (
237-
"apply the exact changes that have been specified (or "
238-
"determined from the commit log), disabling logic that "
239-
"guesses the next version based on typical version "
240-
"progression when a prelease suffix is present."
238+
"set the method by which the new version is chosen. "
239+
"'linear' (default) guesses the next version based on typical linear version progression, "
240+
"such that bumping of a pre-release with lower precedence than the current pre-release "
241+
"phase maintains the current phase of higher precedence. "
242+
"'exact' applies the changes that have been specified (or determined from the commit log) "
243+
"without interpretation, such that the increment and pre-release are always honored"
241244
),
242245
},
243246
{

Diff for: commitizen/commands/bump.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
5252
"tag_format",
5353
"prerelease",
5454
"increment",
55-
"exact_increment",
55+
"increment_mode",
5656
"bump_message",
5757
"gpg_sign",
5858
"annotated_tag",
@@ -159,7 +159,7 @@ def __call__(self) -> None: # noqa: C901
159159
is_local_version: bool = self.arguments["local_version"]
160160
manual_version = self.arguments["manual_version"]
161161
build_metadata = self.arguments["build_metadata"]
162-
exact_increment: bool = self.arguments["exact_increment"]
162+
increment_mode: str = self.arguments["increment_mode"]
163163

164164
if manual_version:
165165
if increment:
@@ -254,7 +254,7 @@ def __call__(self) -> None: # noqa: C901
254254
devrelease=devrelease,
255255
is_local_version=is_local_version,
256256
build_metadata=build_metadata,
257-
exact_increment=exact_increment,
257+
exact_increment=increment_mode == "exact",
258258
)
259259

260260
new_tag_version = bump.normalize_tag(

Diff for: docs/bump.md

+20-17
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ options:
7979
specify non-negative integer for dev. release
8080
--increment {MAJOR,MINOR,PATCH}
8181
manually specify the desired increment
82-
--exact-increment apply the exact changes that have been specified (or determined from the commit log), disabling logic that guesses the next version based on typical version progression when a prelease suffix is present.
82+
--increment-mode
83+
set the method by which the new version is chosen. 'linear' (default) guesses the next version based
84+
on typical linear version progression, such that bumping of a pre-release with lower precedence than
85+
the current pre-release phase maintains the current phase of higher precedence. 'exact' applies the
86+
changes that have been specified (or determined from the commit log) without interpretation, such that
87+
the increment and pre-release are always honored
8388
--check-consistency, -cc
8489
check consistency among versions defined in commitizen configuration and version_files
8590
--annotated-tag, -at create annotated tag instead of lightweight one
@@ -140,29 +145,27 @@ by their precedence and showcase how a release might flow through a development
140145
- `1.1.0rc0` after bumping the release candidate
141146
- `1.1.0` next feature release
142147
143-
Also note that bumping pre-releases _maintains linearity_: bumping of a pre-release with lower precedence than
144-
the current pre-release phase maintains the current phase of higher precedence. For example, if the current
145-
version is `1.0.0b1` then bumping with `--prerelease alpha` will continue to bump the “beta” phase.
146-
This behavior can be overridden by passing `--exact-increment` (see below).
148+
### `--increment-mode`
147149
148-
### `--exact-increment`
150+
By default, `--increment-mode` is set to `linear`, which ensures taht bumping pre-releases _maintains linearity_:
151+
bumping of a pre-release with lower precedence than the current pre-release phase maintains the current phase of
152+
higher precedence. For example, if the current version is `1.0.0b1` then bumping with `--prerelease alpha` will
153+
continue to bump the “beta” phase.
149154
150-
The `--exact-increment` flag bypasses the logic that creates a best guess for the next version based on the
151-
principle of maintaining linearity when a pre-release is present (see above). Instead, `bump` will apply the
155+
Setting `--increment-mode` to `exact` instructs `cz bump` to instead apply the
152156
exact changes that have been specified with `--increment` or determined from the commit log. For example,
153157
`--prerelease beta` will always result in a `b` tag, and `--increment PATCH` will always increase the patch component.
154158
155159
Below are some examples that illustrate the difference in behavior:
156160
157-
158-
| Increment | Pre-release | Start Version | Without `--exact-increment` | With `--exact-increment` |
159-
|-----------|-------------|---------------|-----------------------------|--------------------------|
160-
| `MAJOR` | | `2.0.0b0` | `2.0.0` | `3.0.0` |
161-
| `MINOR` | | `2.0.0b0` | `2.0.0` | `2.1.0` |
162-
| `PATCH` | | `2.0.0b0` | `2.0.0` | `2.0.1` |
163-
| `MAJOR` | `alpha` | `2.0.0b0` | `3.0.0a0` | `3.0.0a0` |
164-
| `MINOR` | `alpha` | `2.0.0b0` | `2.0.0b1` | `2.1.0a0` |
165-
| `PATCH` | `alpha` | `2.0.0b0` | `2.0.0b1` | `2.0.1a0` |
161+
| Increment | Pre-release | Start Version | `--increment-mode=linear` | `--increment-mode=exact` |
162+
|-----------|-------------|---------------|---------------------------|--------------------------|
163+
| `MAJOR` | | `2.0.0b0` | `2.0.0` | `3.0.0` |
164+
| `MINOR` | | `2.0.0b0` | `2.0.0` | `2.1.0` |
165+
| `PATCH` | | `2.0.0b0` | `2.0.0` | `2.0.1` |
166+
| `MAJOR` | `alpha` | `2.0.0b0` | `3.0.0a0` | `3.0.0a0` |
167+
| `MINOR` | `alpha` | `2.0.0b0` | `2.0.0b1` | `2.1.0a0` |
168+
| `PATCH` | `alpha` | `2.0.0b0` | `2.0.0b1` | `2.0.1a0` |
166169
167170
### `--check-consistency`
168171

Diff for: tests/commands/test_bump_command.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -327,34 +327,48 @@ def test_bump_command_prelease_exact_mode(mocker: MockFixture):
327327
assert tag_exists is True
328328

329329
# PRERELEASE + PATCH BUMP
330-
testargs = ["cz", "bump", "--prerelease", "alpha", "--yes", "--exact-increment"]
330+
testargs = [
331+
"cz",
332+
"bump",
333+
"--prerelease",
334+
"alpha",
335+
"--yes",
336+
"--increment-mode=exact",
337+
]
331338
mocker.patch.object(sys, "argv", testargs)
332339
cli.main()
333340

334341
tag_exists = git.tag_exist("0.2.0a1")
335342
assert tag_exists is True
336343

337344
# PRERELEASE + MINOR BUMP
338-
# --exact-increment allows the minor version to bump, and restart the prerelease
345+
# --increment-mode allows the minor version to bump, and restart the prerelease
339346
create_file_and_commit("feat: location")
340347

341-
testargs = ["cz", "bump", "--prerelease", "alpha", "--yes", "--exact-increment"]
348+
testargs = [
349+
"cz",
350+
"bump",
351+
"--prerelease",
352+
"alpha",
353+
"--yes",
354+
"--increment-mode=exact",
355+
]
342356
mocker.patch.object(sys, "argv", testargs)
343357
cli.main()
344358

345359
tag_exists = git.tag_exist("0.3.0a0")
346360
assert tag_exists is True
347361

348362
# PRERELEASE + MAJOR BUMP
349-
# --exact-increment allows the major version to bump, and restart the prerelease
363+
# --increment-mode=exact allows the major version to bump, and restart the prerelease
350364
testargs = [
351365
"cz",
352366
"bump",
353367
"--prerelease",
354368
"alpha",
355369
"--yes",
356370
"--increment=MAJOR",
357-
"--exact-increment",
371+
"--increment-mode=exact",
358372
]
359373
mocker.patch.object(sys, "argv", testargs)
360374
cli.main()

0 commit comments

Comments
 (0)