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
experimental/szager/collated-output
tyoshino@chromium.org 12 years ago
parent afadfca503
commit c1737d0609

@ -367,6 +367,9 @@ class Settings(object):
def GetDefaultCCList(self): def GetDefaultCCList(self):
return self._GetConfig('rietveld.cc', error_ok=True) return self._GetConfig('rietveld.cc', error_ok=True)
def GetDefaultPrivateFlag(self):
return self._GetConfig('rietveld.private', error_ok=True)
def GetIsGerrit(self): def GetIsGerrit(self):
"""Return true if this repo is assosiated with gerrit code review system.""" """Return true if this repo is assosiated with gerrit code review system."""
if self.is_gerrit is None: if self.is_gerrit is None:
@ -807,6 +810,8 @@ def GetCodereviewSettingsInteractively():
RunGit(['config', 'rietveld.' + name, new_val]) RunGit(['config', 'rietveld.' + name, new_val])
SetProperty(settings.GetDefaultCCList(), 'CC list', 'cc', False) 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', SetProperty(settings.GetTreeStatusUrl(error_ok=True), 'Tree status URL',
'tree-status-url', False) 'tree-status-url', False)
SetProperty(settings.GetViewVCUrl(), 'ViewVC URL', 'viewvc-url', True) 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. # Only server setting is required. Other settings can be absent.
# In that case, we ignore errors raised during option deletion attempt. # In that case, we ignore errors raised during option deletion attempt.
SetProperty('cc', 'CC_LIST', unset_error_ok=True) 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('tree-status-url', 'STATUS', unset_error_ok=True)
SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True) SetProperty('viewvc-url', 'VIEW_VC', unset_error_ok=True)
@ -1268,6 +1274,9 @@ def RietveldUpload(options, args, cl):
if cc: if cc:
upload_args.extend(['--cc', 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)]) upload_args.extend(['--git_similarity', str(options.similarity)])
if not options.find_copies: if not options.find_copies:
upload_args.extend(['--git_no_find_copies']) upload_args.extend(['--git_no_find_copies'])
@ -1350,6 +1359,8 @@ def CMDupload(parser, args):
help="Emulate Subversion's auto properties feature.") help="Emulate Subversion's auto properties feature.")
parser.add_option('-c', '--use-commit-queue', action='store_true', parser.add_option('-c', '--use-commit-queue', action='store_true',
help='tell the commit queue to commit this patchset') 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', parser.add_option('--target_branch',
help='When uploading to gerrit, remote branch to ' help='When uploading to gerrit, remote branch to '
'use for CL. Default: master') 'use for CL. Default: master')

@ -109,9 +109,9 @@ class TestGitCl(TestCase):
return result return result
@classmethod @classmethod
def _upload_calls(cls, similarity, find_copies): def _upload_calls(cls, similarity, find_copies, private):
return (cls._git_base_calls(similarity, find_copies) + return (cls._git_base_calls(similarity, find_copies) +
cls._git_upload_calls()) cls._git_upload_calls(private))
@classmethod @classmethod
def _upload_no_rev_calls(cls, similarity, find_copies): def _upload_no_rev_calls(cls, similarity, find_copies):
@ -186,26 +186,33 @@ class TestGitCl(TestCase):
] ]
@classmethod @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 [ return [
((['git', '--no-pager', 'config', 'core.editor'],), ''), ((['git', '--no-pager', 'config', 'core.editor'],), ''),
((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), ((['git', '--no-pager', 'config', 'rietveld.cc'],), '')
((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''), ] + private_call + [
((['git', '--no-pager', ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''),
'config', '--local', '--get-regexp', '^svn-remote\\.'],), ((['git', '--no-pager',
(('', None), 0)), 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''), (('', None), 0)),
((['git', '--no-pager', 'svn', 'info'],), ''), ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
((['git', '--no-pager', ((['git', '--no-pager', 'svn', 'info'],), ''),
'config', 'branch.master.rietveldissue', '1'],), ''), ((['git', '--no-pager',
((['git', '--no-pager', 'config', 'branch.master.rietveldserver', 'config', 'branch.master.rietveldissue', '1'],), ''),
'https://codereview.example.com'],), ''), ((['git', '--no-pager', 'config', 'branch.master.rietveldserver',
((['git', '--no-pager', 'https://codereview.example.com'],), ''),
'config', 'branch.master.rietveldpatchset', '2'],), ''), ((['git', '--no-pager',
((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'), 'config', 'branch.master.rietveldpatchset', '2'],), ''),
((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'), ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'),
((['git', '--no-pager', ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'),
'config', 'branch.hash.last-upload-hash', 'hash'],), ''), ((['git', '--no-pager',
'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
] ]
@staticmethod @staticmethod
@ -336,7 +343,7 @@ class TestGitCl(TestCase):
] ]
@staticmethod @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().""" """Returns the upload command line passed to upload.RealMain()."""
return [ return [
'upload', '--assume_yes', '--server', 'upload', '--assume_yes', '--server',
@ -344,6 +351,7 @@ class TestGitCl(TestCase):
'--message', description '--message', description
] + args + [ ] + args + [
'--cc', 'joe@example.com', '--cc', 'joe@example.com',
] + (['--private'] if private else []) + [
'--git_similarity', similarity or '50' '--git_similarity', similarity or '50'
] + (['--git_no_find_copies'] if find_copies == False else []) + [ ] + (['--git_no_find_copies'] if find_copies == False else []) + [
'fake_ancestor_sha', 'HEAD' 'fake_ancestor_sha', 'HEAD'
@ -355,7 +363,8 @@ class TestGitCl(TestCase):
expected_description, expected_description,
returned_description, returned_description,
final_description, final_description,
reviewers): reviewers,
private=False):
"""Generic reviewer test framework.""" """Generic reviewer test framework."""
try: try:
similarity = upload_args[upload_args.index('--similarity')+1] similarity = upload_args[upload_args.index('--similarity')+1]
@ -369,7 +378,9 @@ class TestGitCl(TestCase):
else: else:
find_copies = None 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): def RunEditor(desc, _, **kwargs):
self.assertEquals( self.assertEquals(
'# Enter a description of the change.\n' '# Enter a description of the change.\n'
@ -381,7 +392,7 @@ class TestGitCl(TestCase):
self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
def check_upload(args): def check_upload(args):
cmd_line = self._cmd_line(final_description, reviewers, similarity, cmd_line = self._cmd_line(final_description, reviewers, similarity,
find_copies) find_copies, private)
self.assertEquals(cmd_line, args) self.assertEquals(cmd_line, args)
return 1, 2 return 1, 2
self.mock(git_cl.upload, 'RealMain', check_upload) self.mock(git_cl.upload, 'RealMain', check_upload)
@ -411,6 +422,14 @@ class TestGitCl(TestCase):
'desc\n\nBUG=', '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): def test_reviewers_cmd_line(self):
# Reviewer is passed as-is # Reviewer is passed as-is
description = 'desc\n\nR=foo@example.com\nBUG=' description = 'desc\n\nR=foo@example.com\nBUG='
@ -630,6 +649,8 @@ class TestGitCl(TestCase):
((['git', '--no-pager', 'config', 'rietveld.server', ((['git', '--no-pager', 'config', 'rietveld.server',
'gerrit.chromium.org'],), ''), 'gerrit.chromium.org'],), ''),
((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''), ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''),
((['git', '--no-pager', 'config', '--unset-all',
'rietveld.private'],), ''),
((['git', '--no-pager', 'config', '--unset-all', ((['git', '--no-pager', 'config', '--unset-all',
'rietveld.tree-status-url'],), ''), 'rietveld.tree-status-url'],), ''),
((['git', '--no-pager', 'config', '--unset-all', ((['git', '--no-pager', 'config', '--unset-all',
@ -654,6 +675,8 @@ class TestGitCl(TestCase):
''), ''),
((['git', '--no-pager', 'config', 'rietveld.cc'],), ''), ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
(('CC list:',), ''), (('CC list:',), ''),
((['git', '--no-pager', 'config', 'rietveld.private'],), ''),
(('Private flag (rietveld only):',), ''),
((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''), ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''),
(('Tree status URL:',), ''), (('Tree status URL:',), ''),
((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''), ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''),

Loading…
Cancel
Save