Skip to content
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

Propagate current_version and new_version to commit #70

Merged
merged 4 commits into from Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -161,6 +161,15 @@ General configuration is grouped in a `[bumpversion]` section.

Also available as `(--commit | --no-commit)`.

In many projects it is common to have a pre-commit hook that runs prior to a
commit and in case of failure aborts the commit. For some use cases it might
be desired that when bumping a version and having `commit = True`, the
pre-commit hook should perform slightly different actions than in regular
commits. For example run an extended set of checks only for actual releases of
the software. To allow the pre-commit hooks to distinguish a bumpversion
commit, the `BUMPVERSION_CURRENT_VERSION` and `BUMPVERSION_NEW_VERSION`
environment variables are set when executing the commit command.

#### `message =`
_**[optional]**_<br />
**default:** `Bump version: {current_version} → {new_version}`
Expand Down
2 changes: 1 addition & 1 deletion bumpversion/cli.py
Expand Up @@ -662,7 +662,7 @@ def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args):
commit_message,
)
if do_commit:
vcs.commit(message=commit_message)
vcs.commit(message=commit_message, context=context)
return context


Expand Down
6 changes: 4 additions & 2 deletions bumpversion/vcs.py
Expand Up @@ -10,7 +10,7 @@

from bumpversion.exceptions import (
WorkingDirectoryIsDirtyException,
MercurialDoesNotSupportSignedTagsException
MercurialDoesNotSupportSignedTagsException,
)
from bumpversion.compat import _command_args

Expand All @@ -24,11 +24,13 @@ class BaseVCS(object):
_COMMIT_COMMAND = None

@classmethod
def commit(cls, message):
def commit(cls, message, context):
with NamedTemporaryFile("wb", delete=False) as f:
f.write(message.encode("utf-8"))
env = os.environ.copy()
env[str("HGENCODING")] = str("utf-8")
for key in ("current_version", "new_version"):
env[str("BUMPVERSION_" + key.upper())] = str(context[key])
try:
subprocess.check_output(cls._COMMIT_COMMAND + [f.name], env=env)
except subprocess.CalledProcessError as exc:
Expand Down