Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3b8b829

Browse files
feat(bump): add flag --local-version that supports bumping only the local version instead of the public
1 parent ae03624 commit 3b8b829

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

commitizen/bump.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ def semver_generator(current_version: str, increment: str = None) -> str:
108108

109109

110110
def generate_version(
111-
current_version: str, increment: str, prerelease: Optional[str] = None
111+
current_version: str,
112+
increment: str,
113+
prerelease: Optional[str] = None,
114+
is_local_version: bool = False,
112115
) -> Version:
113116
"""Based on the given increment a proper semver will be generated.
114117
@@ -122,10 +125,18 @@ def generate_version(
122125
MAJOR 1.0.0 -> 2.0.0
123126
"""
124127
pre_version = prerelease_generator(current_version, prerelease=prerelease)
125-
semver = semver_generator(current_version, increment=increment)
126-
# TODO: post version
127-
# TODO: dev version
128-
return Version(f"{semver}{pre_version}")
128+
129+
if is_local_version:
130+
version = Version(current_version)
131+
local_semver = semver_generator(str(version.local), increment=increment)
132+
133+
return Version(f"{version.public}+{local_semver}{pre_version}")
134+
else:
135+
semver = semver_generator(current_version, increment=increment)
136+
137+
# TODO: post version
138+
# TODO: dev version
139+
return Version(f"{semver}{pre_version}")
129140

130141

131142
def update_version_in_files(

commitizen/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
"action": "store_true",
8282
"help": "bump version in the files from the config",
8383
},
84+
{
85+
"name": "--local-version",
86+
"action": "store_true",
87+
"help": "bump only the local version portion",
88+
},
8489
{
8590
"name": ["--changelog", "-ch"],
8691
"action": "store_true",

commitizen/commands/bump.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __call__(self): # noqa: C901
9292
increment: Optional[str] = self.arguments["increment"]
9393
prerelease: str = self.arguments["prerelease"]
9494
is_files_only: Optional[bool] = self.arguments["files_only"]
95+
is_local_version: Optional[bool] = self.arguments["local_version"]
9596

9697
current_tag_version: str = bump.create_tag(
9798
current_version, tag_format=tag_format
@@ -117,7 +118,10 @@ def __call__(self): # noqa: C901
117118
increment = None
118119

119120
new_version = bump.generate_version(
120-
current_version, increment, prerelease=prerelease
121+
current_version,
122+
increment,
123+
prerelease=prerelease,
124+
is_local_version=is_local_version,
121125
)
122126
new_tag_version = bump.create_tag(new_version, tag_format=tag_format)
123127
message = bump.create_commit_message(
@@ -140,7 +144,7 @@ def __call__(self): # noqa: C901
140144

141145
bump.update_version_in_files(
142146
current_version,
143-
new_version.public,
147+
str(new_version),
144148
version_files,
145149
check_consistency=self.check_consistency,
146150
)
@@ -159,7 +163,7 @@ def __call__(self): # noqa: C901
159163
changelog_cmd()
160164
c = cmd.run(f"git add {changelog_cmd.file_name}")
161165

162-
self.config.set_key("version", new_version.public)
166+
self.config.set_key("version", str(new_version))
163167
c = git.commit(message, args=self._get_commit_args())
164168
if c.return_code != 0:
165169
raise BumpCommitFailedError(f'git.commit error: "{c.err.strip()}"')

0 commit comments

Comments
 (0)