From c1737d0609bb514556bd82d86af25488c326ae8d Mon Sep 17 00:00:00 2001 From: "tyoshino@chromium.org" Date: Wed, 29 May 2013 14:17:28 +0000 Subject: [PATCH] Add --private option to git_cl.py TEST=tests/git_cl_test.py Review URL: https://chromiumcodereview.appspot.com/15650014 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@202865 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 11 +++++++ tests/git_cl_test.py | 73 +++++++++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 25 deletions(-) diff --git a/git_cl.py b/git_cl.py index 78032178f..198eb36a5 100755 --- a/git_cl.py +++ b/git_cl.py @@ -367,6 +367,9 @@ class Settings(object): def GetDefaultCCList(self): return self._GetConfig('rietveld.cc', error_ok=True) + def GetDefaultPrivateFlag(self): + return self._GetConfig('rietveld.private', error_ok=True) + def GetIsGerrit(self): """Return true if this repo is assosiated with gerrit code review system.""" if self.is_gerrit is None: @@ -807,6 +810,8 @@ def GetCodereviewSettingsInteractively(): RunGit(['config', 'rietveld.' + name, new_val]) SetProperty(settings.GetDefaultCCList(), 'CC list', 'cc', False) + SetProperty(settings.GetDefaultPrivateFlag(), + 'Private flag (rietveld only)', 'private', False) SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL', 'tree-status-url', False) SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True) @@ -944,6 +949,7 @@ def LoadCodereviewSettingsFromFile(fileobj): # Only server setting is required. Other settings can be absent. # In that case, we ignore errors raised during option deletion attempt. SetProperty('cc', 'CC_LIST', unset_error_ok=True) + SetProperty('private', 'PRIVATE', unset_error_ok=True) SetProperty('tree-status-url', 'STATUS', unset_error_ok=True) SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) @@ -1268,6 +1274,9 @@ def RietveldUpload(options, args, cl): if cc: upload_args.extend(['--cc', cc]) + if options.private or settings.GetDefaultPrivateFlag() == "True": + upload_args.append('--private') + upload_args.extend(['--git_similarity', str(options.similarity)]) if not options.find_copies: upload_args.extend(['--git_no_find_copies']) @@ -1350,6 +1359,8 @@ def CMDupload(parser, args): help="Emulate Subversion's auto properties feature.") parser.add_option('-c', '--use-commit-queue', action='store_true', help='tell the commit queue to commit this patchset') + parser.add_option('--private', action='store_true', + help='set the review private (rietveld only)') parser.add_option('--target_branch', help='When uploading to gerrit, remote branch to ' 'use for CL. Default: master') diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 01c5b583c..52bcb6c96 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -109,9 +109,9 @@ class TestGitCl(TestCase): return result @classmethod - def _upload_calls(cls, similarity, find_copies): + def _upload_calls(cls, similarity, find_copies, private): return (cls._git_base_calls(similarity, find_copies) + - cls._git_upload_calls()) + cls._git_upload_calls(private)) @classmethod def _upload_no_rev_calls(cls, similarity, find_copies): @@ -186,26 +186,33 @@ class TestGitCl(TestCase): ] @classmethod - def _git_upload_calls(cls): + def _git_upload_calls(cls, private): + if private: + private_call = [] + else: + private_call = [ + ((['git', '--no-pager', 'config', 'rietveld.private'],), '')] + return [ - ((['git', '--no-pager', 'config', 'core.editor'],), ''), - ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), - ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), - ((['git', '--no-pager', - 'config', '--local', '--get-regexp', '^svn-remote\\.'],), - (('', None), 0)), - ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), - ((['git', '--no-pager', 'svn', 'info'],), ''), - ((['git', '--no-pager', - 'config', 'branch.master.rietveldissue', '1'],), ''), - ((['git', '--no-pager', 'config', 'branch.master.rietveldserver', - 'https://codereview.example.com'],), ''), - ((['git', '--no-pager', - 'config', 'branch.master.rietveldpatchset', '2'],), ''), - ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'), - ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'), - ((['git', '--no-pager', - 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), + ((['git', '--no-pager', 'config', 'core.editor'],), ''), + ((['git', '--no-pager', 'config', 'rietveld.cc'],), '') + ] + private_call + [ + ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), + ((['git', '--no-pager', + 'config', '--local', '--get-regexp', '^svn-remote\\.'],), + (('', None), 0)), + ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), + ((['git', '--no-pager', 'svn', 'info'],), ''), + ((['git', '--no-pager', + 'config', 'branch.master.rietveldissue', '1'],), ''), + ((['git', '--no-pager', 'config', 'branch.master.rietveldserver', + 'https://codereview.example.com'],), ''), + ((['git', '--no-pager', + 'config', 'branch.master.rietveldpatchset', '2'],), ''), + ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'), + ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'), + ((['git', '--no-pager', + 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), ] @staticmethod @@ -336,7 +343,7 @@ class TestGitCl(TestCase): ] @staticmethod - def _cmd_line(description, args, similarity, find_copies): + def _cmd_line(description, args, similarity, find_copies, private): """Returns the upload command line passed to upload.RealMain().""" return [ 'upload', '--assume_yes', '--server', @@ -344,6 +351,7 @@ class TestGitCl(TestCase): '--message', description ] + args + [ '--cc', 'joe@example.com', + ] + (['--private'] if private else []) + [ '--git_similarity', similarity or '50' ] + (['--git_no_find_copies'] if find_copies == False else []) + [ 'fake_ancestor_sha', 'HEAD' @@ -355,7 +363,8 @@ class TestGitCl(TestCase): expected_description, returned_description, final_description, - reviewers): + reviewers, + private=False): """Generic reviewer test framework.""" try: similarity = upload_args[upload_args.index('--similarity')+1] @@ -369,7 +378,9 @@ class TestGitCl(TestCase): else: find_copies = None - self.calls = self._upload_calls(similarity, find_copies) + private = '--private' in upload_args + + self.calls = self._upload_calls(similarity, find_copies, private) def RunEditor(desc, _, **kwargs): self.assertEquals( '# Enter a description of the change.\n' @@ -381,7 +392,7 @@ class TestGitCl(TestCase): self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) def check_upload(args): cmd_line = self._cmd_line(final_description, reviewers, similarity, - find_copies) + find_copies, private) self.assertEquals(cmd_line, args) return 1, 2 self.mock(git_cl.upload, 'RealMain', check_upload) @@ -411,6 +422,14 @@ class TestGitCl(TestCase): 'desc\n\nBUG=', []) + def test_private(self): + self._run_reviewer_test( + ['--private'], + 'desc\n\nBUG=', + '# Blah blah comment.\ndesc\n\nBUG=\n', + 'desc\n\nBUG=', + []) + def test_reviewers_cmd_line(self): # Reviewer is passed as-is description = 'desc\n\nR=foo@example.com\nBUG=' @@ -630,6 +649,8 @@ class TestGitCl(TestCase): ((['git', '--no-pager', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''), + ((['git', '--no-pager', 'config', '--unset-all', + 'rietveld.private'],), ''), ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), ((['git', '--no-pager', 'config', '--unset-all', @@ -654,6 +675,8 @@ class TestGitCl(TestCase): ''), ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), (('CC list:',), ''), + ((['git', '--no-pager', 'config', 'rietveld.private'],), ''), + (('Private flag (rietveld only):',), ''), ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), (('Tree status URL:',), ''), ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''),