diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 877fd11..c9f029d 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -152,7 +152,9 @@ def tag(cls, name, message): command = ["git", "tag", name] if message: command += ['--message', message] - subprocess.check_output(command) + elif message is None: + command += ['--annotate'] + subprocess.check_call(command) class Mercurial(BaseVCS): @@ -187,7 +189,9 @@ def tag(cls, name, message): command = ["hg", "tag", name] if message: command += ['--message', message] - subprocess.check_output(command) + elif message is None: + command += ['--edit'] + subprocess.check_call(command) VCS = [Git, Mercurial] @@ -786,7 +790,7 @@ def main(original_args=None): help='Tag name (only works with --tag)', default=defaults.get('tag_name', 'v{new_version}')) - parser3.add_argument('--tag-message', metavar='TAG_MESSAGE', dest='tag_message', + parser3.add_argument('--tag-message', metavar='TAG_MESSAGE', dest='tag_message', nargs='?', help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} → {new_version}')) parser3.add_argument('--message', '-m', metavar='COMMIT_MSG', @@ -804,11 +808,11 @@ def main(original_args=None): nargs='*', help='Files to change', default=file_names) - args = parser3.parse_args(remaining_argv + positionals) + args = parser3.parse_args(positionals + remaining_argv) if args.dry_run: logger.info("Dry run active, won't touch any files.") - + if args.new_version: new_version = vc.parse(args.new_version) @@ -922,11 +926,13 @@ def main(original_args=None): vcs.commit(message=commit_message) tag_name = args.tag_name.format(**vcs_context) - tag_message = args.tag_message.format(**vcs_context) + tag_message = (args.tag_message.format(**vcs_context) + if args.tag_message is not None else None) logger.info("{} '{}' {} in {}".format( "Would tag" if not do_tag else "Tagging", tag_name, - "with message '{}'".format(tag_message) if tag_message else "without message", + ("with message from editor" if tag_message is None else + "with message '{}'".format(tag_message)), vcs.__name__ )) diff --git a/tests/test_cli.py b/tests/test_cli.py index bf5a067..260aec1 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -79,7 +79,6 @@ def _mock_calls_to_string(called_mock): [--commit | --no-commit] [--tag | --no-tag] [--tag-name TAG_NAME] -[--tag-message TAG_MESSAGE] [--message COMMIT_MSG] part [file [file ...]] @@ -121,7 +120,7 @@ def _mock_calls_to_string(called_mock): --no-tag Do not create a tag in version control --tag-name TAG_NAME Tag name (only works with --tag) (default: v{new_version}) - --tag-message TAG_MESSAGE + --tag-message [TAG_MESSAGE] Tag message (default: Bump version: {current_version} → {new_version}) --message COMMIT_MSG, -m COMMIT_MSG @@ -788,6 +787,21 @@ def test_annotated_tag(tmpdir, vcs): raise ValueError("Unknown VCS") +@pytest.mark.parametrize(("vcs"), [xfail_if_no_git("git"), xfail_if_no_hg("hg")]) +def test_annotated_editor_tag(tmpdir, vcs): + tmpdir.chdir() + check_call([vcs, "init"]) + tmpdir.join("VERSION").write("42.4.1") + check_call([vcs, "add", "VERSION"]) + check_call([vcs, "commit", "-m", "initial commit"]) + + with mock.patch("bumpversion.logger") as logger: + main(['patch', '--current-version', '42.4.1', '--commit', '--tag', 'VERSION', '--dry-run', '--tag-message']) + + actual_log ="\n".join(_mock_calls_to_string(logger)[4:]) + assert "Would tag 'v42.4.2' with message from editor" in actual_log + + @pytest.mark.parametrize(("vcs"), [xfail_if_no_git("git")]) def test_vcs_describe(tmpdir, vcs): tmpdir.chdir()