Skip to content

Commit 4d1205c

Browse files
Merge branch 'commitizen-tools:master' into fix/regression_since_v2.27.0_untracked_changelog_gets_git_added
2 parents a4adfa4 + 0e026d4 commit 4d1205c

File tree

10 files changed

+132
-68
lines changed

10 files changed

+132
-68
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
- id: no-commit-to-branch
1515

1616
- repo: https://github.com/commitizen-tools/commitizen
17-
rev: v2.32.5 # automatically updated by Commitizen
17+
rev: v2.33.0 # automatically updated by Commitizen
1818
hooks:
1919
- id: commitizen
2020
- id: commitizen-branch

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11

2+
## v2.33.0 (2022-09-15)
3+
4+
### Feat
5+
6+
- add functionality for dev-releases
7+
8+
## v2.32.7 (2022-09-14)
9+
10+
### Fix
11+
12+
- **README.md**: fix pre-commit install command
13+
14+
## v2.32.6 (2022-09-14)
15+
16+
### Fix
17+
18+
- **bump**: log git commit stderr and stdout during bump
19+
220
## v2.32.5 (2022-09-10)
321

422
### Fix

commitizen/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.32.5"
1+
__version__ = "2.33.0"

commitizen/bump.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ def prerelease_generator(current_version: str, prerelease: Optional[str] = None)
6969
return pre_version
7070

7171

72+
def devrelease_generator(devrelease: int = None) -> str:
73+
"""Generate devrelease
74+
75+
The devrelease version should be passed directly and is not
76+
inferred based on the previous version.
77+
"""
78+
if devrelease is None:
79+
return ""
80+
81+
return f"dev{devrelease}"
82+
83+
7284
def semver_generator(current_version: str, increment: str = None) -> str:
7385
version = Version(current_version)
7486
prev_release = list(version.release)
@@ -102,6 +114,7 @@ def generate_version(
102114
current_version: str,
103115
increment: str,
104116
prerelease: Optional[str] = None,
117+
devrelease: Optional[int] = None,
105118
is_local_version: bool = False,
106119
) -> Version:
107120
"""Based on the given increment a proper semver will be generated.
@@ -117,17 +130,18 @@ def generate_version(
117130
"""
118131
if is_local_version:
119132
version = Version(current_version)
133+
dev_version = devrelease_generator(devrelease=devrelease)
120134
pre_version = prerelease_generator(str(version.local), prerelease=prerelease)
121135
semver = semver_generator(str(version.local), increment=increment)
122136

123-
return Version(f"{version.public}+{semver}{pre_version}")
137+
return Version(f"{version.public}+{semver}{pre_version}{dev_version}")
124138
else:
139+
dev_version = devrelease_generator(devrelease=devrelease)
125140
pre_version = prerelease_generator(current_version, prerelease=prerelease)
126141
semver = semver_generator(current_version, increment=increment)
127142

128143
# TODO: post version
129-
# TODO: dev version
130-
return Version(f"{semver}{pre_version}")
144+
return Version(f"{semver}{pre_version}{dev_version}")
131145

132146

133147
def update_version_in_files(

commitizen/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@
141141
"help": "choose type of prerelease",
142142
"choices": ["alpha", "beta", "rc"],
143143
},
144+
{
145+
"name": ["--devrelease", "-d"],
146+
"help": "specify non-negative integer for dev. release",
147+
"type": int,
148+
},
144149
{
145150
"name": ["--increment"],
146151
"help": "manually specify the desired increment",

commitizen/commands/bump.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __call__(self): # noqa: C901
103103
is_yes: bool = self.arguments["yes"]
104104
increment: Optional[str] = self.arguments["increment"]
105105
prerelease: str = self.arguments["prerelease"]
106+
devrelease: Optional[int] = self.arguments["devrelease"]
106107
is_files_only: Optional[bool] = self.arguments["files_only"]
107108
is_local_version: Optional[bool] = self.arguments["local_version"]
108109

@@ -151,6 +152,7 @@ def __call__(self): # noqa: C901
151152
current_version,
152153
increment,
153154
prerelease=prerelease,
155+
devrelease=devrelease,
154156
is_local_version=is_local_version,
155157
)
156158

@@ -234,6 +236,12 @@ def __call__(self): # noqa: C901
234236
c = git.commit(message, args=self._get_commit_args())
235237
if c.return_code != 0:
236238
raise BumpCommitFailedError(f'2nd git.commit error: "{c.err.strip()}"')
239+
240+
if c.out:
241+
out.write(c.out)
242+
if c.err:
243+
out.write(c.err)
244+
237245
c = git.tag(
238246
new_tag_version,
239247
signed=self.bump_settings.get("gpg_sign", False)

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ repos:
120120
After the configuration is added, you'll need to run:
121121
122122
```sh
123-
pre-commit install --hook-type commit-msg pre-push
123+
pre-commit install --hook-type commit-msg --hook-type pre-push
124124
```
125125

126126
If you aren't using both hooks, you needn't install both stages.

docs/bump.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ Some examples:
4848
2.0.1a
4949
```
5050

51-
`post` and `dev` releases are not supported yet.
51+
`post` releases are not supported yet.
5252

5353
## Usage
5454

5555
```bash
5656
$ cz bump --help
5757
usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
5858
[--no-verify] [--yes] [--tag-format TAG_FORMAT]
59-
[--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}]
60-
[--increment {MAJOR,MINOR,PATCH}] [--check-consistency]
61-
[--annotated-tag] [--gpg-sign] [--changelog-to-stdout] [--retry]
59+
[--bump-message BUMP_MESSAGE] [--increment {MAJOR,MINOR,PATCH}]
60+
[--prerelease {alpha,beta,rc}] [--devrelease {DEV}]
61+
[--check-consistency] [--annotated-tag] [--gpg-sign]
62+
[--changelog-to-stdout] [--retry]
6263

6364
options:
6465
-h, --help show this help message and exit
@@ -77,6 +78,7 @@ options:
7778
when working with CI
7879
--prerelease {alpha,beta,rc}, -pr {alpha,beta,rc}
7980
choose type of prerelease
81+
--devrelease {DEV} specify dev release
8082
--increment {MAJOR,MINOR,PATCH}
8183
manually specify the desired increment
8284
--check-consistency, -cc
@@ -269,7 +271,7 @@ cz bump --tag-format="v$version"
269271
```
270272
271273
```bash
272-
cz bump --tag-format="v$minor.$major.$patch$prerelease"
274+
cz bump --tag-format="v$minor.$major.$patch$prerelease.$devrelease"
273275
```
274276
275277
In your `pyproject.toml` or `.cz.toml`
@@ -283,13 +285,14 @@ The variables must be preceded by a `$` sign.
283285
284286
Supported variables:
285287
286-
| Variable | Description |
287-
| ------------- | ------------------------------------------ |
288-
| `$version` | full generated version |
289-
| `$major` | MAJOR increment |
290-
| `$minor` | MINOR increment |
291-
| `$patch` | PATCH increment |
292-
| `$prerelease` | Prerelase (alpha, beta, release candidate) |
288+
| Variable | Description |
289+
| ------------- | --------------------------------------------|
290+
| `$version` | full generated version |
291+
| `$major` | MAJOR increment |
292+
| `$minor` | MINOR increment |
293+
| `$patch` | PATCH increment |
294+
| `$prerelease` | Prerelease (alpha, beta, release candidate) |
295+
| `$devrelease` | Development release |
293296
294297
---
295298

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.commitizen]
2-
version = "2.32.5"
2+
version = "2.33.0"
33
tag_format = "v$version"
44
version_files = [
55
"pyproject.toml:version",
@@ -30,7 +30,7 @@ exclude = '''
3030

3131
[tool.poetry]
3232
name = "commitizen"
33-
version = "2.32.5"
33+
version = "2.33.0"
3434
description = "Python commitizen client tool"
3535
authors = ["Santiago Fraire <santiwilly@gmail.com>"]
3636
license = "MIT"

tests/test_bump_find_version.py

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,72 @@
66
from commitizen.bump import generate_version
77

88
simple_flow = [
9-
(("0.1.0", "PATCH", None), "0.1.1"),
10-
(("0.1.1", "MINOR", None), "0.2.0"),
11-
(("0.2.0", "MINOR", None), "0.3.0"),
12-
(("0.3.0", "PATCH", None), "0.3.1"),
13-
(("0.3.0", "PATCH", "alpha"), "0.3.1a0"),
14-
(("0.3.1a0", None, "alpha"), "0.3.1a1"),
15-
(("0.3.1a0", None, None), "0.3.1"),
16-
(("0.3.1", "PATCH", None), "0.3.2"),
17-
(("0.4.2", "MAJOR", "alpha"), "1.0.0a0"),
18-
(("1.0.0a0", None, "alpha"), "1.0.0a1"),
19-
(("1.0.0a1", None, "alpha"), "1.0.0a2"),
20-
(("1.0.0a1", None, "beta"), "1.0.0b0"),
21-
(("1.0.0b0", None, "beta"), "1.0.0b1"),
22-
(("1.0.0b1", None, "rc"), "1.0.0rc0"),
23-
(("1.0.0rc0", None, "rc"), "1.0.0rc1"),
24-
(("1.0.0rc0", "PATCH", None), "1.0.0"),
25-
(("1.0.0", "PATCH", None), "1.0.1"),
26-
(("1.0.1", "PATCH", None), "1.0.2"),
27-
(("1.0.2", "MINOR", None), "1.1.0"),
28-
(("1.1.0", "MINOR", None), "1.2.0"),
29-
(("1.2.0", "PATCH", None), "1.2.1"),
30-
(("1.2.1", "MAJOR", None), "2.0.0"),
9+
(("0.1.0", "PATCH", None, None), "0.1.1"),
10+
(("0.1.0", "PATCH", None, 1), "0.1.1.dev1"),
11+
(("0.1.1", "MINOR", None, None), "0.2.0"),
12+
(("0.2.0", "MINOR", None, None), "0.3.0"),
13+
(("0.2.0", "MINOR", None, 1), "0.3.0.dev1"),
14+
(("0.3.0", "PATCH", None, None), "0.3.1"),
15+
(("0.3.0", "PATCH", "alpha", None), "0.3.1a0"),
16+
(("0.3.1a0", None, "alpha", None), "0.3.1a1"),
17+
(("0.3.1a0", None, None, None), "0.3.1"),
18+
(("0.3.1", "PATCH", None, None), "0.3.2"),
19+
(("0.4.2", "MAJOR", "alpha", None), "1.0.0a0"),
20+
(("1.0.0a0", None, "alpha", None), "1.0.0a1"),
21+
(("1.0.0a1", None, "alpha", None), "1.0.0a2"),
22+
(("1.0.0a1", None, "alpha", 1), "1.0.0a2.dev1"),
23+
(("1.0.0a2.dev0", None, "alpha", 1), "1.0.0a3.dev1"),
24+
(("1.0.0a2.dev0", None, "alpha", 0), "1.0.0a3.dev0"),
25+
(("1.0.0a1", None, "beta", None), "1.0.0b0"),
26+
(("1.0.0b0", None, "beta", None), "1.0.0b1"),
27+
(("1.0.0b1", None, "rc", None), "1.0.0rc0"),
28+
(("1.0.0rc0", None, "rc", None), "1.0.0rc1"),
29+
(("1.0.0rc0", None, "rc", 1), "1.0.0rc1.dev1"),
30+
(("1.0.0rc0", "PATCH", None, None), "1.0.0"),
31+
(("1.0.0a3.dev0", None, "beta", None), "1.0.0b0"),
32+
(("1.0.0", "PATCH", None, None), "1.0.1"),
33+
(("1.0.1", "PATCH", None, None), "1.0.2"),
34+
(("1.0.2", "MINOR", None, None), "1.1.0"),
35+
(("1.1.0", "MINOR", None, None), "1.2.0"),
36+
(("1.2.0", "PATCH", None, None), "1.2.1"),
37+
(("1.2.1", "MAJOR", None, None), "2.0.0"),
3138
]
3239

3340
local_versions = [
34-
(("4.5.0+0.1.0", "PATCH", None), "4.5.0+0.1.1"),
35-
(("4.5.0+0.1.1", "MINOR", None), "4.5.0+0.2.0"),
36-
(("4.5.0+0.2.0", "MAJOR", None), "4.5.0+1.0.0"),
41+
(("4.5.0+0.1.0", "PATCH", None, None), "4.5.0+0.1.1"),
42+
(("4.5.0+0.1.1", "MINOR", None, None), "4.5.0+0.2.0"),
43+
(("4.5.0+0.2.0", "MAJOR", None, None), "4.5.0+1.0.0"),
3744
]
3845

3946
# this cases should be handled gracefully
4047
unexpected_cases = [
41-
(("0.1.1rc0", None, "alpha"), "0.1.1a0"),
42-
(("0.1.1b1", None, "alpha"), "0.1.1a0"),
48+
(("0.1.1rc0", None, "alpha", None), "0.1.1a0"),
49+
(("0.1.1b1", None, "alpha", None), "0.1.1a0"),
4350
]
4451

4552
weird_cases = [
46-
(("1.1", "PATCH", None), "1.1.1"),
47-
(("1", "MINOR", None), "1.1.0"),
48-
(("1", "MAJOR", None), "2.0.0"),
49-
(("1a0", None, "alpha"), "1.0.0a1"),
50-
(("1", None, "beta"), "1.0.0b0"),
51-
(("1beta", None, "beta"), "1.0.0b1"),
52-
(("1.0.0alpha1", None, "alpha"), "1.0.0a2"),
53-
(("1", None, "rc"), "1.0.0rc0"),
54-
(("1.0.0rc1+e20d7b57f3eb", "PATCH", None), "1.0.0"),
53+
(("1.1", "PATCH", None, None), "1.1.1"),
54+
(("1", "MINOR", None, None), "1.1.0"),
55+
(("1", "MAJOR", None, None), "2.0.0"),
56+
(("1a0", None, "alpha", None), "1.0.0a1"),
57+
(("1", None, "beta", None), "1.0.0b0"),
58+
(("1beta", None, "beta", None), "1.0.0b1"),
59+
(("1.0.0alpha1", None, "alpha", None), "1.0.0a2"),
60+
(("1", None, "rc", None), "1.0.0rc0"),
61+
(("1.0.0rc1+e20d7b57f3eb", "PATCH", None, None), "1.0.0"),
5562
]
5663

5764
# test driven development
5865
tdd_cases = [
59-
(("0.1.1", "PATCH", None), "0.1.2"),
60-
(("0.1.1", "MINOR", None), "0.2.0"),
61-
(("2.1.1", "MAJOR", None), "3.0.0"),
62-
(("0.9.0", "PATCH", "alpha"), "0.9.1a0"),
63-
(("0.9.0", "MINOR", "alpha"), "0.10.0a0"),
64-
(("0.9.0", "MAJOR", "alpha"), "1.0.0a0"),
65-
(("1.0.0a2", None, "beta"), "1.0.0b0"),
66-
(("1.0.0beta1", None, "rc"), "1.0.0rc0"),
67-
(("1.0.0rc1", None, "rc"), "1.0.0rc2"),
66+
(("0.1.1", "PATCH", None, None), "0.1.2"),
67+
(("0.1.1", "MINOR", None, None), "0.2.0"),
68+
(("2.1.1", "MAJOR", None, None), "3.0.0"),
69+
(("0.9.0", "PATCH", "alpha", None), "0.9.1a0"),
70+
(("0.9.0", "MINOR", "alpha", None), "0.10.0a0"),
71+
(("0.9.0", "MAJOR", "alpha", None), "1.0.0a0"),
72+
(("1.0.0a2", None, "beta", None), "1.0.0b0"),
73+
(("1.0.0beta1", None, "rc", None), "1.0.0rc0"),
74+
(("1.0.0rc1", None, "rc", None), "1.0.0rc2"),
6875
]
6976

7077

@@ -76,9 +83,16 @@ def test_generate_version(test_input, expected):
7683
current_version = test_input[0]
7784
increment = test_input[1]
7885
prerelease = test_input[2]
79-
assert generate_version(
80-
current_version, increment=increment, prerelease=prerelease
81-
) == Version(expected)
86+
devrelease = test_input[3]
87+
assert (
88+
generate_version(
89+
current_version,
90+
increment=increment,
91+
prerelease=prerelease,
92+
devrelease=devrelease,
93+
)
94+
== Version(expected)
95+
)
8296

8397

8498
@pytest.mark.parametrize(
@@ -89,12 +103,14 @@ def test_generate_version_local(test_input, expected):
89103
current_version = test_input[0]
90104
increment = test_input[1]
91105
prerelease = test_input[2]
106+
devrelease = test_input[3]
92107
is_local_version = True
93108
assert (
94109
generate_version(
95110
current_version,
96111
increment=increment,
97112
prerelease=prerelease,
113+
devrelease=devrelease,
98114
is_local_version=is_local_version,
99115
)
100116
== Version(expected)

0 commit comments

Comments
 (0)