|
@@ -808,31 +808,19 @@ class TestGitCl(unittest.TestCase):
|
|
|
|
|
|
return calls
|
|
|
|
|
|
- def _gerrit_upload_calls(self,
|
|
|
- description,
|
|
|
- reviewers,
|
|
|
- squash,
|
|
|
+ def _gerrit_upload_calls(self, description, reviewers, squash,
|
|
|
squash_mode='default',
|
|
|
- title=None,
|
|
|
- notify=False,
|
|
|
- post_amend_description=None,
|
|
|
- issue=None,
|
|
|
- cc=None,
|
|
|
- custom_cl_base=None,
|
|
|
- tbr=None,
|
|
|
+ title=None, notify=False,
|
|
|
+ post_amend_description=None, issue=None, cc=None,
|
|
|
+ custom_cl_base=None, tbr=None,
|
|
|
short_hostname='chromium',
|
|
|
- labels=None,
|
|
|
- change_id=None,
|
|
|
- final_description=None,
|
|
|
- gitcookies_exists=True,
|
|
|
- force=False,
|
|
|
- edit_description=None,
|
|
|
- default_branch='master',
|
|
|
- push_opts=None):
|
|
|
+ labels=None, change_id=None,
|
|
|
+ final_description=None, gitcookies_exists=True,
|
|
|
+ force=False, edit_description=None,
|
|
|
+ default_branch='master'):
|
|
|
if post_amend_description is None:
|
|
|
post_amend_description = description
|
|
|
cc = cc or []
|
|
|
- push_opts = push_opts if push_opts else []
|
|
|
|
|
|
calls = []
|
|
|
|
|
@@ -888,18 +876,17 @@ class TestGitCl(unittest.TestCase):
|
|
|
((['git', 'rev-list', parent + '..' + ref_to_push],),'1hashPerLine\n'),
|
|
|
]
|
|
|
|
|
|
-
|
|
|
- metrics_arguments = [arg for arg in push_opts if arg != '-o']
|
|
|
+ metrics_arguments = []
|
|
|
|
|
|
if notify:
|
|
|
- push_opts += ['-o', 'ready', '-o', 'notify=ALL']
|
|
|
+ ref_suffix = '%ready,notify=ALL'
|
|
|
metrics_arguments += ['ready', 'notify=ALL']
|
|
|
else:
|
|
|
if not issue and squash:
|
|
|
- push_opts += ['-o', 'wip']
|
|
|
+ ref_suffix = '%wip'
|
|
|
metrics_arguments.append('wip')
|
|
|
else:
|
|
|
- push_opts += ['-o', 'notify=NONE']
|
|
|
+ ref_suffix = '%notify=NONE'
|
|
|
metrics_arguments.append('notify=NONE')
|
|
|
|
|
|
# If issue is given, then description is fetched from Gerrit instead.
|
|
@@ -914,19 +901,18 @@ class TestGitCl(unittest.TestCase):
|
|
|
]
|
|
|
title = 'User input'
|
|
|
if title:
|
|
|
- push_opts += ['-o', 'm=' + gerrit_util.PercentEncodeForGitRef(title)]
|
|
|
+ ref_suffix += ',m=' + gerrit_util.PercentEncodeForGitRef(title)
|
|
|
metrics_arguments.append('m')
|
|
|
|
|
|
if short_hostname == 'chromium':
|
|
|
# All reviewers and ccs get into ref_suffix.
|
|
|
for r in sorted(reviewers):
|
|
|
- push_opts += ['-o', 'r=%s' % r]
|
|
|
+ ref_suffix += ',r=%s' % r
|
|
|
metrics_arguments.append('r')
|
|
|
-
|
|
|
if issue is None:
|
|
|
cc += ['test-more-cc@chromium.org', 'joe@example.com']
|
|
|
for c in sorted(cc):
|
|
|
- push_opts += ['-o', 'cc=%s' % c]
|
|
|
+ ref_suffix += ',cc=%s' % c
|
|
|
metrics_arguments.append('cc')
|
|
|
reviewers, cc = [], []
|
|
|
else:
|
|
@@ -942,19 +928,19 @@ class TestGitCl(unittest.TestCase):
|
|
|
]
|
|
|
for r in sorted(reviewers):
|
|
|
if r != 'bad-account-or-email':
|
|
|
- push_opts += ['-o', 'r=%s' % r]
|
|
|
+ ref_suffix += ',r=%s' % r
|
|
|
metrics_arguments.append('r')
|
|
|
reviewers.remove(r)
|
|
|
if issue is None:
|
|
|
cc += ['joe@example.com']
|
|
|
for c in sorted(cc):
|
|
|
- push_opts += ['-o', 'cc=%s' % c]
|
|
|
+ ref_suffix += ',cc=%s' % c
|
|
|
metrics_arguments.append('cc')
|
|
|
if c in cc:
|
|
|
cc.remove(c)
|
|
|
|
|
|
for k, v in sorted((labels or {}).items()):
|
|
|
- push_opts += ['-o', 'l=%s+%d' % (k, v)]
|
|
|
+ ref_suffix += ',l=%s+%d' % (k, v)
|
|
|
metrics_arguments.append('l=%s+%d' % (k, v))
|
|
|
|
|
|
if tbr:
|
|
@@ -966,46 +952,35 @@ class TestGitCl(unittest.TestCase):
|
|
|
]
|
|
|
|
|
|
calls += [
|
|
|
- (
|
|
|
- ('time.time', ),
|
|
|
- 1000,
|
|
|
- ),
|
|
|
- (
|
|
|
- ([
|
|
|
- 'git', 'push',
|
|
|
- 'https://%s.googlesource.com/my/repo' % short_hostname,
|
|
|
- ref_to_push + ':refs/for/refs/heads/' + default_branch
|
|
|
- ] + push_opts, ),
|
|
|
- (('remote:\n'
|
|
|
- 'remote: Processing changes: (\)\n'
|
|
|
- 'remote: Processing changes: (|)\n'
|
|
|
- 'remote: Processing changes: (/)\n'
|
|
|
- 'remote: Processing changes: (-)\n'
|
|
|
- 'remote: Processing changes: new: 1 (/)\n'
|
|
|
- 'remote: Processing changes: new: 1, done\n'
|
|
|
- 'remote:\n'
|
|
|
- 'remote: New Changes:\n'
|
|
|
- 'remote: '
|
|
|
- 'https://%s-review.googlesource.com/#/c/my/repo/+/123456'
|
|
|
- ' XXX\n'
|
|
|
- 'remote:\n'
|
|
|
- 'To https://%s.googlesource.com/my/repo\n'
|
|
|
- ' * [new branch] hhhh -> refs/for/refs/heads/%s\n') %
|
|
|
- (short_hostname, short_hostname, default_branch)),
|
|
|
- ),
|
|
|
- (
|
|
|
- ('time.time', ),
|
|
|
- 2000,
|
|
|
- ),
|
|
|
- (
|
|
|
- ('add_repeated', 'sub_commands', {
|
|
|
- 'execution_time': 1000,
|
|
|
- 'command': 'git push',
|
|
|
- 'exit_code': 0,
|
|
|
- 'arguments': sorted(metrics_arguments),
|
|
|
- }),
|
|
|
- None,
|
|
|
- ),
|
|
|
+ (('time.time',), 1000,),
|
|
|
+ ((['git', 'push',
|
|
|
+ 'https://%s.googlesource.com/my/repo' % short_hostname,
|
|
|
+ ref_to_push + ':refs/for/refs/heads/' + default_branch + ref_suffix],),
|
|
|
+ (('remote:\n'
|
|
|
+ 'remote: Processing changes: (\)\n'
|
|
|
+ 'remote: Processing changes: (|)\n'
|
|
|
+ 'remote: Processing changes: (/)\n'
|
|
|
+ 'remote: Processing changes: (-)\n'
|
|
|
+ 'remote: Processing changes: new: 1 (/)\n'
|
|
|
+ 'remote: Processing changes: new: 1, done\n'
|
|
|
+ 'remote:\n'
|
|
|
+ 'remote: New Changes:\n'
|
|
|
+ 'remote: https://%s-review.googlesource.com/#/c/my/repo/+/123456'
|
|
|
+ ' XXX\n'
|
|
|
+ 'remote:\n'
|
|
|
+ 'To https://%s.googlesource.com/my/repo\n'
|
|
|
+ ' * [new branch] hhhh -> refs/for/refs/heads/%s\n'
|
|
|
+ ) % (short_hostname, short_hostname, default_branch)),),
|
|
|
+ (('time.time',), 2000,),
|
|
|
+ (('add_repeated',
|
|
|
+ 'sub_commands',
|
|
|
+ {
|
|
|
+ 'execution_time': 1000,
|
|
|
+ 'command': 'git push',
|
|
|
+ 'exit_code': 0,
|
|
|
+ 'arguments': sorted(metrics_arguments),
|
|
|
+ }),
|
|
|
+ None,),
|
|
|
]
|
|
|
|
|
|
final_description = final_description or post_amend_description.strip()
|
|
@@ -1112,32 +1087,32 @@ class TestGitCl(unittest.TestCase):
|
|
|
]
|
|
|
return calls
|
|
|
|
|
|
- def _run_gerrit_upload_test(self,
|
|
|
- upload_args,
|
|
|
- description,
|
|
|
- reviewers=None,
|
|
|
- squash=True,
|
|
|
- squash_mode=None,
|
|
|
- title=None,
|
|
|
- notify=False,
|
|
|
- post_amend_description=None,
|
|
|
- issue=None,
|
|
|
- cc=None,
|
|
|
- fetched_status=None,
|
|
|
- other_cl_owner=None,
|
|
|
- custom_cl_base=None,
|
|
|
- tbr=None,
|
|
|
- short_hostname='chromium',
|
|
|
- labels=None,
|
|
|
- change_id=None,
|
|
|
- final_description=None,
|
|
|
- gitcookies_exists=True,
|
|
|
- force=False,
|
|
|
- log_description=None,
|
|
|
- edit_description=None,
|
|
|
- fetched_description=None,
|
|
|
- default_branch='master',
|
|
|
- push_opts=None):
|
|
|
+ def _run_gerrit_upload_test(
|
|
|
+ self,
|
|
|
+ upload_args,
|
|
|
+ description,
|
|
|
+ reviewers=None,
|
|
|
+ squash=True,
|
|
|
+ squash_mode=None,
|
|
|
+ title=None,
|
|
|
+ notify=False,
|
|
|
+ post_amend_description=None,
|
|
|
+ issue=None,
|
|
|
+ cc=None,
|
|
|
+ fetched_status=None,
|
|
|
+ other_cl_owner=None,
|
|
|
+ custom_cl_base=None,
|
|
|
+ tbr=None,
|
|
|
+ short_hostname='chromium',
|
|
|
+ labels=None,
|
|
|
+ change_id=None,
|
|
|
+ final_description=None,
|
|
|
+ gitcookies_exists=True,
|
|
|
+ force=False,
|
|
|
+ log_description=None,
|
|
|
+ edit_description=None,
|
|
|
+ fetched_description=None,
|
|
|
+ default_branch='master'):
|
|
|
"""Generic gerrit upload test framework."""
|
|
|
if squash_mode is None:
|
|
|
if '--no-squash' in upload_args:
|
|
@@ -1217,17 +1192,12 @@ class TestGitCl(unittest.TestCase):
|
|
|
'gclient_utils.temporary_file', TemporaryFileMock()).start()
|
|
|
mock.patch('os.remove', return_value=True).start()
|
|
|
self.calls += self._gerrit_upload_calls(
|
|
|
- description,
|
|
|
- reviewers,
|
|
|
- squash,
|
|
|
+ description, reviewers, squash,
|
|
|
squash_mode=squash_mode,
|
|
|
- title=title,
|
|
|
- notify=notify,
|
|
|
+ title=title, notify=notify,
|
|
|
post_amend_description=post_amend_description,
|
|
|
- issue=issue,
|
|
|
- cc=cc,
|
|
|
- custom_cl_base=custom_cl_base,
|
|
|
- tbr=tbr,
|
|
|
+ issue=issue, cc=cc,
|
|
|
+ custom_cl_base=custom_cl_base, tbr=tbr,
|
|
|
short_hostname=short_hostname,
|
|
|
labels=labels,
|
|
|
change_id=change_id,
|
|
@@ -1235,8 +1205,7 @@ class TestGitCl(unittest.TestCase):
|
|
|
gitcookies_exists=gitcookies_exists,
|
|
|
force=force,
|
|
|
edit_description=edit_description,
|
|
|
- default_branch=default_branch,
|
|
|
- push_opts=push_opts)
|
|
|
+ default_branch=default_branch)
|
|
|
# Uncomment when debugging.
|
|
|
# print('\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))))
|
|
|
git_cl.main(['upload'] + upload_args)
|
|
@@ -1291,24 +1260,16 @@ class TestGitCl(unittest.TestCase):
|
|
|
squash_mode='override_nosquash',
|
|
|
change_id='I123456789')
|
|
|
|
|
|
- def test_gerrit_push_opts(self):
|
|
|
- self._run_gerrit_upload_test(['-o', 'wip'],
|
|
|
- 'desc ✔\n\nBUG=\n\nChange-Id: I123456789\n',
|
|
|
- [],
|
|
|
- squash=False,
|
|
|
- squash_mode='override_nosquash',
|
|
|
- change_id='I123456789',
|
|
|
- push_opts=['-o', 'wip'])
|
|
|
-
|
|
|
def test_gerrit_no_reviewer_non_chromium_host(self):
|
|
|
# TODO(crbug/877717): remove this test case.
|
|
|
- self._run_gerrit_upload_test([],
|
|
|
- 'desc ✔\n\nBUG=\n\nChange-Id: I123456789\n',
|
|
|
- [],
|
|
|
- squash=False,
|
|
|
- squash_mode='override_nosquash',
|
|
|
- short_hostname='other',
|
|
|
- change_id='I123456789')
|
|
|
+ self._run_gerrit_upload_test(
|
|
|
+ [],
|
|
|
+ 'desc ✔\n\nBUG=\n\nChange-Id: I123456789\n',
|
|
|
+ [],
|
|
|
+ squash=False,
|
|
|
+ squash_mode='override_nosquash',
|
|
|
+ short_hostname='other',
|
|
|
+ change_id='I123456789')
|
|
|
|
|
|
def test_gerrit_patchset_title_special_chars_nosquash(self):
|
|
|
self._run_gerrit_upload_test(
|