@@ -143,6 +143,7 @@ def _increment_version(
143
143
prerelease : bool ,
144
144
prerelease_token : str ,
145
145
major_on_zero : bool ,
146
+ allow_zero_version : bool ,
146
147
) -> Version :
147
148
"""
148
149
Using the given versions, along with a given `level_bump`, increment to
@@ -158,19 +159,29 @@ def _increment_version(
158
159
`latest_full_version_in_history`, correspondingly, is the latest full release which
159
160
is in this branch's history.
160
161
"""
162
+ local_vars = list (locals ().items ())
161
163
log .debug (
162
- "_increment_version: %s" , ", " .join (f"{ k } = { v } " for k , v in locals (). items () )
164
+ "_increment_version: %s" , ", " .join (f"{ k } = { v } " for k , v in local_vars )
163
165
)
164
- if not major_on_zero and latest_version .major == 0 :
165
- # if we are a 0.x.y release and have set `major_on_zero`,
166
- # breaking changes should increment the minor digit
167
- # Correspondingly, we reduce the level that we increment the
168
- # version by.
169
- log .debug (
170
- "reducing version increment due to 0. version and major_on_zero=False"
171
- )
166
+ if latest_version .major == 0 :
167
+ if not allow_zero_version :
168
+ # Set up default version to be 1.0.0 if currently 0.x.x which means a commented
169
+ # breaking change is not required to bump to 1.0.0
170
+ log .debug (
171
+ "Bumping major version as 0.x.x versions are disabled because of allow_zero_version=False"
172
+ )
173
+ level_bump = LevelBump .MAJOR
174
+
175
+ elif not major_on_zero :
176
+ # if we are a 0.x.y release and have set `major_on_zero`,
177
+ # breaking changes should increment the minor digit
178
+ # Correspondingly, we reduce the level that we increment the
179
+ # version by.
180
+ log .debug (
181
+ "reducing version increment due to 0. version and major_on_zero=False"
182
+ )
172
183
173
- level_bump = min (level_bump , LevelBump .MINOR )
184
+ level_bump = min (level_bump , LevelBump .MINOR )
174
185
175
186
if prerelease :
176
187
log .debug ("prerelease=true" )
@@ -261,6 +272,7 @@ def next_version(
261
272
commit_parser : CommitParser [ParseResult , ParserOptions ],
262
273
prerelease : bool = False ,
263
274
major_on_zero : bool = True ,
275
+ allow_zero_version : bool = True ,
264
276
) -> Version :
265
277
"""
266
278
Evaluate the history within `repo`, and based on the tags and commits in the repo
@@ -398,8 +410,9 @@ def next_version(
398
410
level_bump = max (parsed_levels , default = LevelBump .NO_RELEASE )
399
411
log .info ("The type of the next release release is: %s" , level_bump )
400
412
if level_bump is LevelBump .NO_RELEASE :
401
- log .info ("No release will be made" )
402
- return latest_version
413
+ if latest_version .major != 0 or allow_zero_version :
414
+ log .info ("No release will be made" )
415
+ return latest_version
403
416
404
417
return _increment_version (
405
418
latest_version = latest_version ,
@@ -418,4 +431,5 @@ def next_version(
418
431
prerelease = prerelease ,
419
432
prerelease_token = translator .prerelease_token ,
420
433
major_on_zero = major_on_zero ,
434
+ allow_zero_version = allow_zero_version ,
421
435
)
0 commit comments