From 68bf7f83e5341cc6c64549feb7d1bbacc90dfc9f Mon Sep 17 00:00:00 2001 From: Gert Van Gool Date: Sun, 21 Apr 2013 19:57:45 +0200 Subject: [PATCH 1/2] Creates annotated tags When creating annotated tags (by passing a message into them), you can use "git describe". --- bumpversion/__init__.py | 9 +++++++-- tests.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index aa5da38..52e7640 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -5,6 +5,7 @@ import os import warnings import re +import shlex import sre_constants import subprocess from string import Formatter @@ -121,6 +122,8 @@ def main(args=None): parser3.add_argument('--message', '-m', metavar='COMMIT_MSG', help='Commit message', default='Bump version: {current_version} → {new_version}') + parser3.add_argument('--tag-options', metavar='TAG_OPTIONS', + dest='tag_options', help='Extra tag options for the tag command, e.g. --sign') files = [] if 'files' in defaults: @@ -185,5 +188,7 @@ def main(args=None): subprocess.check_call( ["git", "commit", "-m", args.message.format(**formatargs)]) if args.tag: - subprocess.check_call( - ["git", "tag", "v{new_version}".format(**formatargs)]) + tag_args = ["git", "tag", "v{new_version}".format(**formatargs)] + if args.tag_options: + tag_args.extend(shlex.split(args.tag_options.format(**formatargs))) + subprocess.check_call(tag_args) diff --git a/tests.py b/tests.py index 39cf775..bf1eb47 100644 --- a/tests.py +++ b/tests.py @@ -23,6 +23,7 @@ def test_usage_string(tmpdir, capsys): usage: py.test [-h] [--config-file FILE] [--bump PART] [--parse REGEX] [--serialize FORMAT] [--current-version VERSION] [--dry-run] --new-version VERSION [--commit] [--tag] [--message COMMIT_MSG] + [--tag-options TAG_OPTIONS] file [file ...] Bumps version strings @@ -50,6 +51,9 @@ def test_usage_string(tmpdir, capsys): --message COMMIT_MSG, -m COMMIT_MSG Commit message (default: Bump version: {current_version} → {new_version}) + --tag-options TAG_OPTIONS + Extra tag options for the tag command, e.g. --sign + (default: None) """.lstrip() @@ -220,6 +224,21 @@ def test_git_commit(tmpdir): assert 'v47.1.3' in tag_out + describe_out = subprocess.call(["git", "describe"]) + assert 128 == describe_out + + main(['--current-version', '47.1.3', '--commit', '--tag', '--tag-options', '"-m \\"test v{new_version}-tag\\""', 'VERSION']) + + assert '47.1.4' == tmpdir.join("VERSION").read() + + tag_out = subprocess.check_output(["git", "tag"]) + + assert 'v47.1.4' in tag_out + + describe_out = subprocess.check_output(["git", "describe"]) + + assert 'v47.1.4' in describe_out + def test_bump_version_ENV(tmpdir): From 125e58e5fdbf34387af25c5678de1d89f3d20e88 Mon Sep 17 00:00:00 2001 From: Gert Van Gool Date: Sun, 21 Apr 2013 20:24:47 +0200 Subject: [PATCH 2/2] Create annotated tags for bumpversion --- .bumpversion.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d3f1745..4e634ee 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -3,4 +3,5 @@ current_version = 0.1.1 files = setup.py commit = True tag = True +tag_options = -m "bumpversion v{new_version}"