From dcbfb32b0536900d5d6aa0809421b84a164812ad Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 10 Sep 2018 13:00:35 +0200 Subject: [PATCH] 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 --- git_review/cmd.py | 16 ++++++++++------ git_review/tests/test_git_review.py | 9 +++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/git_review/cmd.py b/git_review/cmd.py index a36011f2..aa13973e 100755 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -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") diff --git a/git_review/tests/test_git_review.py b/git_review/tests/test_git_review.py index cd3fc91f..fe778f88 100644 --- a/git_review/tests/test_git_review.py +++ b/git_review/tests/test_git_review.py @@ -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):