Skip to content

feat(bump): add support to bumping local version #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def semver_generator(current_version: str, increment: str = None) -> str:


def generate_version(
current_version: str, increment: str, prerelease: Optional[str] = None
current_version: str,
increment: str,
prerelease: Optional[str] = None,
is_local_version: bool = False,
) -> Version:
"""Based on the given increment a proper semver will be generated.

Expand All @@ -122,10 +125,18 @@ def generate_version(
MAJOR 1.0.0 -> 2.0.0
"""
pre_version = prerelease_generator(current_version, prerelease=prerelease)
semver = semver_generator(current_version, increment=increment)
# TODO: post version
# TODO: dev version
return Version(f"{semver}{pre_version}")

if is_local_version:
version = Version(current_version)
local_semver = semver_generator(str(version.local), increment=increment)

return Version(f"{version.public}+{local_semver}{pre_version}")
else:
semver = semver_generator(current_version, increment=increment)

# TODO: post version
# TODO: dev version
return Version(f"{semver}{pre_version}")


def update_version_in_files(
Expand Down
5 changes: 5 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
"action": "store_true",
"help": "bump version in the files from the config",
},
{
"name": "--local-version",
"action": "store_true",
"help": "bump only the local version portion",
},
{
"name": ["--changelog", "-ch"],
"action": "store_true",
Expand Down
10 changes: 7 additions & 3 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __call__(self): # noqa: C901
increment: Optional[str] = self.arguments["increment"]
prerelease: str = self.arguments["prerelease"]
is_files_only: Optional[bool] = self.arguments["files_only"]
is_local_version: Optional[bool] = self.arguments["local_version"]

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

new_version = bump.generate_version(
current_version, increment, prerelease=prerelease
current_version,
increment,
prerelease=prerelease,
is_local_version=is_local_version,
)
new_tag_version = bump.create_tag(new_version, tag_format=tag_format)
message = bump.create_commit_message(
Expand All @@ -140,7 +144,7 @@ def __call__(self): # noqa: C901

bump.update_version_in_files(
current_version,
new_version.public,
str(new_version),
version_files,
check_consistency=self.check_consistency,
)
Expand All @@ -159,7 +163,7 @@ def __call__(self): # noqa: C901
changelog_cmd()
c = cmd.run(f"git add {changelog_cmd.file_name}")

self.config.set_key("version", new_version.public)
self.config.set_key("version", str(new_version))
c = git.commit(message, args=self._get_commit_args())
if c.return_code != 0:
raise BumpCommitFailedError(f'git.commit error: "{c.err.strip()}"')
Expand Down