diff --git a/README.rst b/README.rst index f685ac8..3d2d3e0 100644 --- a/README.rst +++ b/README.rst @@ -41,6 +41,10 @@ If you want to supply a review topic:: git review -t topic/awesome-feature +If you want to disable autogenerated topic:: + + git review -T + If you want to submit a branch for review and then remove the local branch:: git review -f diff --git a/git-review.1 b/git-review.1 index a69324e..dd7bf34 100644 --- a/git-review.1 +++ b/git-review.1 @@ -38,7 +38,7 @@ .Fl s .Op Ar branch .Nm -.Op Fl fnuvDR +.Op Fl fnuvDRT .Op Fl r Ar remote .Op Fl t Ar topic .Op Ar branch @@ -138,6 +138,8 @@ Just run the repo setup commands but don\(aqt submit anything. .It Fl t Ar topic , Fl \-topic= Ns Ar topic Sets the target topic for this change on the gerrit server. If not specified, a bug number from the commit summary will be used. Alternatively, the local branch name will be used if different from remote branch. +.It Fl T , Fl \-no\-topic +Submit review without topic. .It Fl u , Fl \-update Skip cached local copies and force updates from network resources. .It Fl l , Fl \-list diff --git a/git_review/cmd.py b/git_review/cmd.py index b3ed903..28cf862 100755 --- a/git_review/cmd.py +++ b/git_review/cmd.py @@ -1056,8 +1056,13 @@ def _main(): parser = argparse.ArgumentParser(usage=usage, description=COPYRIGHT) - parser.add_argument("-t", "--topic", dest="topic", - help="Topic to submit branch to") + topic_arg_group = parser.add_mutually_exclusive_group() + topic_arg_group.add_argument("-t", "--topic", dest="topic", + help="Topic to submit branch to") + topic_arg_group.add_argument("-T", "--no-topic", dest="notopic", + action="store_true", + help="No topic except if explicitly provided") + parser.add_argument("-D", "--draft", dest="draft", action="store_true", help="Submit review as a draft") parser.add_argument("-c", "--compatible", dest="compatible", @@ -1233,8 +1238,11 @@ def _main(): ref = "for" cmd = "git push %s HEAD:refs/%s/%s" % (remote, ref, branch) - topic = options.topic or get_topic(branch) - if topic != branch: + 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 if options.regenerate: print("Amending the commit to regenerate the change id\n") diff --git a/git_review/tests/test_git_review.py b/git_review/tests/test_git_review.py index 5260cdb..66225af 100644 --- a/git_review/tests/test_git_review.py +++ b/git_review/tests/test_git_review.py @@ -186,8 +186,9 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase): self.assertIn('rebase', review_res) self.assertEqual(self._run_git('rev-parse', 'HEAD^1'), head) - def _assert_branch_would_be(self, branch): - output = self._run_git_review('-n') + def _assert_branch_would_be(self, branch, extra_args=None): + extra_args = extra_args or [] + output = self._run_git_review('-n', *extra_args) # last non-empty line should be: # git push gerrit HEAD:refs/publish/master last_line = output.strip().split('\n')[-1] @@ -210,6 +211,11 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase): finally: os.environ.update(LANG=lang_env) + 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']) + def test_bug_topic(self): self._run_git_review('-s') self._simple_change('a change', 'new change for bug 123') @@ -230,6 +236,15 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase): self._simple_change('a change', 'new change not for bluepring\nasdf') self._assert_branch_would_be('master') + 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', extra_args=['-T']) + + def test_git_review_T_t(self): + self.assertRaises(Exception, self._run_git_review, '-T', '-t', 'taz') + def test_git_review_l(self): self._run_git_review('-s')