Skip to content

Commit

Permalink
Merge pull request #70 from mauvilsa/master
Browse files Browse the repository at this point in the history
Propagate current_version and new_version to commit
  • Loading branch information
c4urself committed Aug 25, 2019
2 parents a0fb7b3 + c39248c commit 464802f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
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

0 comments on commit 464802f

Please sign in to comment.