Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 13 additions & 7 deletions bumpversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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',
Expand All @@ -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)

Expand Down Expand Up @@ -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__
))

Expand Down
18 changes: 16 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...]]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down