Use new %topic=XXXX syntax for topic pushes

The old syntax is undocumented and slated to be removed.

Uniformize handling of % options. Previously, combining options could
yield destination refs that look like

   refs/for/BRANCH%wip%private

which tries to switch on a non-existent option "wip%private".

Change-Id: Ia4e97eafbf685fcba78d95370dae08254a2c718b
This commit is contained in:
Han-Wen Nienhuys 2018-09-10 13:00:35 +02:00 committed by Han-Wen NIenhuys
parent 51ab58f3fb
commit dcbfb32b05
2 changed files with 15 additions and 10 deletions

View File

@ -1677,16 +1677,18 @@ def _main():
run_custom_script("draft")
cmd = "git push %s HEAD:refs/%s/%s" % (remote, ref, branch)
push_options = []
if options.topic is not None:
topic = options.topic
else:
topic = None if options.notopic else get_topic(branch)
if topic and topic != branch:
cmd += "/%s" % topic
push_options.append("topic=%s" % topic)
if options.reviewers:
assert_valid_reviewers(options.reviewers)
cmd += "%" + ",".join("r=%s" % r for r in options.reviewers)
push_options += ["r=%s" % r for r in options.reviewers]
if options.regenerate:
print("Amending the commit to regenerate the change id\n")
@ -1700,17 +1702,19 @@ def _main():
"'/^Change-Id:/d'")
if options.wip:
cmd += '\%wip'
push_options.append('wip')
if options.ready:
cmd += '\%ready'
push_options.append('ready')
if options.private:
cmd += '\%private'
push_options.append('private')
if options.remove_private:
cmd += '\%remove-private'
push_options.append('remove-private')
if push_options:
cmd += "%" + ",".join(push_options)
if options.dry:
print("Please use the following command "
"to send your commits to review:\n")

View File

@ -386,12 +386,13 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
def test_git_review_t(self):
self._run_git_review('-s')
self._simple_change('test file modified', 'commit message for bug 654')
self._assert_branch_would_be('master/zat', extra_args=['-t', 'zat'])
self._assert_branch_would_be('master%topic=zat',
extra_args=['-t', 'zat'])
def test_bug_topic(self):
self._run_git_review('-s')
self._simple_change('a change', 'new change for bug 123')
self._assert_branch_would_be('master/bug/123')
self._assert_branch_would_be('master%topic=bug/123')
def test_bug_topic_newline(self):
self._run_git_review('-s')
@ -401,7 +402,7 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
def test_bp_topic(self):
self._run_git_review('-s')
self._simple_change('a change', 'new change for blueprint asdf')
self._assert_branch_would_be('master/bp/asdf')
self._assert_branch_would_be('master%topic=bp/asdf')
def test_bp_topic_newline(self):
self._run_git_review('-s')
@ -475,7 +476,7 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
def test_git_review_T(self):
self._run_git_review('-s')
self._simple_change('test file modified', 'commit message for bug 456')
self._assert_branch_would_be('master/bug/456')
self._assert_branch_would_be('master%topic=bug/456')
self._assert_branch_would_be('master', extra_args=['-T'])
def test_git_review_T_t(self):