From 0d6b46e32b99c7f6b7ecef5cde843aaf4e43449a Mon Sep 17 00:00:00 2001 From: Andrii Shyshkalov Date: Fri, 17 Mar 2017 22:23:22 +0100 Subject: [PATCH] git cl comment: require explicit --codereview with -i|--issue flag. R=agable@chromium.org,machenbach@chromium.org BUG=698236 Change-Id: If79f938e457f176c47badd75f78ed4ecb764ec2d Reviewed-on: https://chromium-review.googlesource.com/456700 Commit-Queue: Andrii Shyshkalov Reviewed-by: Michael Achenbach Reviewed-by: Aaron Gable --- git_cl.py | 7 +++++-- tests/git_cl_test.py | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/git_cl.py b/git_cl.py index b63639f75..f65b60da0 100755 --- a/git_cl.py +++ b/git_cl.py @@ -4260,8 +4260,9 @@ def CMDcomments(parser, args): """Shows or posts review comments for any changelist.""" parser.add_option('-a', '--add-comment', dest='comment', help='comment to add to an issue') - parser.add_option('-i', dest='issue', - help='review issue id (defaults to current issue)') + parser.add_option('-i', '--issue', dest='issue', + help='review issue id (defaults to current issue). ' + 'If given, requires --rietveld or --gerrit') parser.add_option('-j', '--json-file', help='File to write JSON summary to') auth.add_auth_options(parser) @@ -4276,6 +4277,8 @@ def CMDcomments(parser, args): issue = int(options.issue) except ValueError: DieWithError('A review issue id is expected to be a number') + if not options.forced_codereview: + parser.error('--gerrit or --rietveld is required if --issue is specified') cl = Changelist(issue=issue, # TODO(tandrii): remove 'rietveld' default. diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index c30d688b5..861d3692d 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -3090,7 +3090,7 @@ class TestGitCl(TestCase): sys.stdout.getvalue(), 'However, your configured .gitcookies file is missing.') - def test_git_cl_comment_add_default(self): + def test_git_cl_comment_add_rietveld(self): self.mock(git_cl._RietveldChangelistImpl, 'AddComment', lambda _, message: self._mocked_call('AddComment', message)) self.calls = [ @@ -3098,8 +3098,8 @@ class TestGitCl(TestCase): ((['git', 'config', 'rietveld.server'],), 'codereview.chromium.org'), (('AddComment', 'msg'), ''), ] - # TODO(tandrii): --rietveld should be specified here. - self.assertEqual(0, git_cl.main(['comment', '-i', '10', '-a', 'msg'])) + self.assertEqual(0, git_cl.main(['comment', '--rietveld', + '-i', '10', '-a', 'msg'])) def test_git_cl_comment_add_gerrit(self): self.mock(git_cl.gerrit_util, 'SetReview',