Skip to content

Commit c6fd959

Browse files
committed
Revert "feat(bump): support prereleases with start offset"
This reverts commit 5702bfe.
1 parent 5702bfe commit c6fd959

File tree

9 files changed

+77
-142
lines changed

9 files changed

+77
-142
lines changed

commitizen/bump.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ def find_increment(
4545
return increment
4646

4747

48-
def prerelease_generator(
49-
current_version: str, prerelease: Optional[str] = None, offset: Optional[int] = 0
50-
) -> str:
48+
def prerelease_generator(current_version: str, prerelease: Optional[str] = None) -> str:
5149
"""Generate prerelease
5250
5351
X.YaN # Alpha release
@@ -67,7 +65,7 @@ def prerelease_generator(
6765
prev_prerelease: int = version.pre[1]
6866
new_prerelease_number = prev_prerelease + 1
6967
else:
70-
new_prerelease_number = offset
68+
new_prerelease_number = 0
7169
pre_version = f"{prerelease}{new_prerelease_number}"
7270
return pre_version
7371

@@ -117,7 +115,6 @@ def generate_version(
117115
current_version: str,
118116
increment: str,
119117
prerelease: Optional[str] = None,
120-
prerelease_offset: int = 0,
121118
devrelease: Optional[int] = None,
122119
is_local_version: bool = False,
123120
) -> Version:
@@ -135,17 +132,13 @@ def generate_version(
135132
if is_local_version:
136133
version = Version(current_version)
137134
dev_version = devrelease_generator(devrelease=devrelease)
138-
pre_version = prerelease_generator(
139-
str(version.local), prerelease=prerelease, offset=prerelease_offset
140-
)
135+
pre_version = prerelease_generator(str(version.local), prerelease=prerelease)
141136
semver = semver_generator(str(version.local), increment=increment)
142137

143138
return Version(f"{version.public}+{semver}{pre_version}{dev_version}")
144139
else:
145140
dev_version = devrelease_generator(devrelease=devrelease)
146-
pre_version = prerelease_generator(
147-
current_version, prerelease=prerelease, offset=prerelease_offset
148-
)
141+
pre_version = prerelease_generator(current_version, prerelease=prerelease)
149142
semver = semver_generator(current_version, increment=increment)
150143

151144
# TODO: post version

commitizen/cli.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@
189189
"default": None,
190190
"help": "keep major version at zero, even for breaking changes",
191191
},
192-
{
193-
"name": ["--prerelease-offset"],
194-
"type": int,
195-
"default": None,
196-
"help": "start pre-releases with this offset",
197-
},
198192
{
199193
"name": "manual_version",
200194
"type": str,

commitizen/commands/bump.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def __init__(self, config: BaseConfig, arguments: dict):
4646
"gpg_sign",
4747
"annotated_tag",
4848
"major_version_zero",
49-
"prerelease_offset",
5049
]
5150
if arguments[key] is not None
5251
},
@@ -104,7 +103,6 @@ def __call__(self): # noqa: C901
104103
bump_commit_message: str = self.bump_settings["bump_message"]
105104
version_files: List[str] = self.bump_settings["version_files"]
106105
major_version_zero: bool = self.bump_settings["major_version_zero"]
107-
prerelease_offset: int = self.bump_settings["prerelease_offset"]
108106

109107
dry_run: bool = self.arguments["dry_run"]
110108
is_yes: bool = self.arguments["yes"]
@@ -135,11 +133,6 @@ def __call__(self): # noqa: C901
135133
"--major-version-zero cannot be combined with MANUAL_VERSION"
136134
)
137135

138-
if prerelease_offset:
139-
raise NotAllowed(
140-
"--prerelease-offset cannot be combined with MANUAL_VERSION"
141-
)
142-
143136
if major_version_zero:
144137
if not current_version.startswith("0."):
145138
raise NotAllowed(
@@ -203,7 +196,6 @@ def __call__(self): # noqa: C901
203196
current_version,
204197
increment,
205198
prerelease=prerelease,
206-
prerelease_offset=prerelease_offset,
207199
devrelease=devrelease,
208200
is_local_version=is_local_version,
209201
)

commitizen/defaults.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class Settings(TypedDict, total=False):
4040
style: Optional[List[Tuple[str, str]]]
4141
customize: CzSettings
4242
major_version_zero: bool
43-
prerelease_offset: int
4443

4544

4645
name: str = "cz_conventional_commits"
@@ -66,7 +65,6 @@ class Settings(TypedDict, total=False):
6665
"update_changelog_on_bump": False,
6766
"use_shortcuts": False,
6867
"major_version_zero": False,
69-
"prerelease_offset": 0,
7068
}
7169

7270
MAJOR = "MAJOR"

docs/bump.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ options:
9595
Output changelog to the stdout
9696
--retry retry commit if it fails the 1st time
9797
--major-version-zero keep major version at zero, even for breaking changes
98-
--prerelease-offset start pre-releases with this offset
9998
```
10099
101100
### `--files-only`
@@ -305,7 +304,7 @@ The variables must be preceded by a `$` sign.
305304
Supported variables:
306305
307306
| Variable | Description |
308-
| ------------- | ------------------------------------------- |
307+
| ------------- | --------------------------------------------|
309308
| `$version` | full generated version |
310309
| `$major` | MAJOR increment |
311310
| `$minor` | MINOR increment |
@@ -412,17 +411,6 @@ Defaults to: `false`
412411
major_version_zero = true
413412
```
414413
415-
### `prerelease_offset`
416-
417-
Offset with which to start counting prereleses.
418-
419-
Defaults to: `0`
420-
421-
```toml
422-
[tool.commitizen]
423-
prerelease_offset = 1
424-
```
425-
426414
## Custom bump
427415
428416
Read the [customizing section](./customization.md).

docs/config.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22

33
## Settings
44

5-
| Variable | Type | Default | Description |
6-
| -------------------------- | ------ | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7-
| `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use |
8-
| `version` | `str` | `None` | Current version. Example: "0.1.2" |
9-
| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] |
10-
| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] |
11-
| `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` |
12-
| `gpg_sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. |
13-
| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] |
14-
| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] |
15-
| `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] |
16-
| `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog |
17-
| `changelog_incremental` | `bool` | `false` | Update changelog with the missing versions. This is good if you don't want to replace previous versions in the file. Note: when doing `cz bump --changelog` this is automatically set to `true` |
18-
| `changelog_start_rev` | `str` | `None` | Start from a given git rev to generate the changelog |
19-
| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] |
20-
| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] |
21-
| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] |
22-
| `major_version_zero` | `bool` | `false` | When true, breaking changes on a `0.x` will remain as a `0.x` version. On `false`, a breaking change will bump a `0.x` version to `1.0`. [major-version-zero] |
23-
| `prerelease_offset` | `int` | `0` | In special cases it may be necessary that a prerelease cannot start with a 0, e.g. in an embedded project the individual characters are encoded in bytes. This can be done by specifying an offset from which to start counting. [prerelease-offset] |
5+
| Variable | Type | Default | Description |
6+
| -------------------------- | ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
7+
| `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use |
8+
| `version` | `str` | `None` | Current version. Example: "0.1.2" |
9+
| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] |
10+
| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] |
11+
| `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` |
12+
| `gpg_sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. |
13+
| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] |
14+
| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] |
15+
| `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] |
16+
| `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog |
17+
| `changelog_incremental` | `bool` | `false` | Update changelog with the missing versions. This is good if you don't want to replace previous versions in the file. Note: when doing `cz bump --changelog` this is automatically set to `true` |
18+
| `changelog_start_rev` | `str` | `None` | Start from a given git rev to generate the changelog |
19+
| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] |
20+
| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] |
21+
| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] |
22+
| `major_version_zero` | `bool` | `false` | When true, breaking changes on a `0.x` will remain as a `0.x` version. On `false`, a breaking change will bump a `0.x` version to `1.0`. [major-version-zero] |
2423

2524
## pyproject.toml or .cz.toml
2625

@@ -116,7 +115,6 @@ commitizen:
116115
[tag_format]: bump.md#tag_format
117116
[bump_message]: bump.md#bump_message
118117
[major-version-zero]: bump.md#-major-version-zero
119-
[prerelease-offset]: bump.md#-prerelease_offset
120118
[allow_abort]: check.md#allow-abort
121119
[additional-features]: https://github.com/tmbo/questionary#additional-features
122120
[customization]: customization.md

tests/commands/test_bump_command.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -759,19 +759,3 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
759759
"--major-version-zero cannot be combined with MANUAL_VERSION"
760760
)
761761
assert expected_error_message in str(excinfo.value)
762-
763-
@pytest.mark.usefixtures("tmp_commitizen_project")
764-
def test_bump_manual_version_disallows_prerelease_offset(mocker):
765-
create_file_and_commit("feat: new file")
766-
767-
manual_version = "0.2.0"
768-
testargs = ["cz", "bump", "--yes", "--prerelease-offset", "42", manual_version]
769-
mocker.patch.object(sys, "argv", testargs)
770-
771-
with pytest.raises(NotAllowed) as excinfo:
772-
cli.main()
773-
774-
expected_error_message = (
775-
"--prerelease-offset cannot be combined with MANUAL_VERSION"
776-
)
777-
assert expected_error_message in str(excinfo.value)

0 commit comments

Comments
 (0)