blob: 68be49f792cccf455404b6dfe0428cfa4c43e64a [file] [log] [blame]
[email protected]ddd59412011-11-30 14:20:381#!/usr/bin/env python
[email protected]eb5edbc2012-01-16 17:03:282# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ddd59412011-11-30 14:20:383# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Unit tests for git_cl.py."""
7
8import os
[email protected]a3353652011-11-30 14:26:579import StringIO
[email protected]78c4b982012-02-14 02:20:2610import stat
[email protected]ddd59412011-11-30 14:20:3811import sys
12import unittest
13
14sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15
16from testing_support.auto_stub import TestCase
17
18import git_cl
[email protected]9e849272014-04-04 00:31:5519import git_common
[email protected]ddd59412011-11-30 14:20:3820import subprocess2
[email protected]ddd59412011-11-30 14:20:3821
[email protected]2e72bb12012-01-17 15:18:3522class PresubmitMock(object):
23 def __init__(self, *args, **kwargs):
24 self.reviewers = []
25 @staticmethod
26 def should_continue():
27 return True
28
29
30class RietveldMock(object):
31 def __init__(self, *args, **kwargs):
32 pass
[email protected]78936cb2013-04-11 00:17:5233
[email protected]2e72bb12012-01-17 15:18:3534 @staticmethod
35 def get_description(issue):
36 return 'Issue: %d' % issue
37
[email protected]78936cb2013-04-11 00:17:5238 @staticmethod
39 def get_issue_properties(_issue, _messages):
40 return {
41 'reviewers': ['[email protected]', '[email protected]'],
42 'messages': [
43 {
44 'approval': True,
45 'sender': '[email protected]',
46 },
47 ],
48 }
49
[email protected]2e72bb12012-01-17 15:18:3550
51class WatchlistsMock(object):
52 def __init__(self, _):
53 pass
54 @staticmethod
55 def GetWatchersForPaths(_):
56 return ['[email protected]']
57
58
[email protected]78c4b982012-02-14 02:20:2659class CodereviewSettingsFileMock(object):
60 def __init__(self):
61 pass
62 # pylint: disable=R0201
63 def read(self):
64 return ("CODE_REVIEW_SERVER: gerrit.chromium.org\n" +
65 "GERRIT_HOST: gerrit.chromium.org\n" +
66 "GERRIT_PORT: 29418\n")
67
68
[email protected]eed4df32015-04-10 21:30:2069class AuthenticatorMock(object):
70 def __init__(self, *_args):
71 pass
72 def has_cached_credentials(self):
73 return True
74
75
[email protected]ddd59412011-11-30 14:20:3876class TestGitCl(TestCase):
77 def setUp(self):
78 super(TestGitCl, self).setUp()
79 self.calls = []
80 self._calls_done = 0
[email protected]2e72bb12012-01-17 15:18:3581 self.mock(subprocess2, 'call', self._mocked_call)
82 self.mock(subprocess2, 'check_call', self._mocked_call)
83 self.mock(subprocess2, 'check_output', self._mocked_call)
84 self.mock(subprocess2, 'communicate', self._mocked_call)
[email protected]71437c02015-04-09 19:29:4085 self.mock(git_common, 'is_dirty_git_tree', lambda x: False)
[email protected]9e849272014-04-04 00:31:5586 self.mock(git_common, 'get_or_create_merge_base',
87 lambda *a: (
88 self._mocked_call(['get_or_create_merge_base']+list(a))))
[email protected]ddd59412011-11-30 14:20:3889 self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '')
[email protected]2e72bb12012-01-17 15:18:3590 self.mock(git_cl, 'ask_for_data', self._mocked_call)
91 self.mock(git_cl.breakpad, 'post', self._mocked_call)
92 self.mock(git_cl.breakpad, 'SendStack', self._mocked_call)
[email protected]ddd59412011-11-30 14:20:3893 self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock)
[email protected]ddd59412011-11-30 14:20:3894 self.mock(git_cl.rietveld, 'Rietveld', RietveldMock)
[email protected]4bac4b52012-11-27 20:33:5295 self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock)
[email protected]ddd59412011-11-30 14:20:3896 self.mock(git_cl.upload, 'RealMain', self.fail)
[email protected]ddd59412011-11-30 14:20:3897 self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock)
[email protected]eed4df32015-04-10 21:30:2098 self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock)
[email protected]24daf9e2015-04-17 02:42:4499 self.mock(git_cl.auth, '_should_use_oauth2', lambda: False)
[email protected]ddd59412011-11-30 14:20:38100 # It's important to reset settings to not have inter-tests interference.
101 git_cl.settings = None
102
103 def tearDown(self):
104 if not self.has_failed():
105 self.assertEquals([], self.calls)
106 super(TestGitCl, self).tearDown()
107
[email protected]9e849272014-04-04 00:31:55108 def _mocked_call(self, *args, **_kwargs):
[email protected]2e72bb12012-01-17 15:18:35109 self.assertTrue(
110 self.calls,
111 '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args))
112 expected_args, result = self.calls.pop(0)
[email protected]e52678e2013-04-26 18:34:44113 # Also logs otherwise it could get caught in a try/finally and be hard to
114 # diagnose.
115 if expected_args != args:
116 msg = '@%d Expected: %r Actual: %r' % (
117 self._calls_done, expected_args, args)
118 git_cl.logging.error(msg)
119 self.fail(msg)
[email protected]2e72bb12012-01-17 15:18:35120 self._calls_done += 1
121 return result
122
[email protected]a3353652011-11-30 14:26:57123 @classmethod
[email protected]c1737d02013-05-29 14:17:28124 def _upload_calls(cls, similarity, find_copies, private):
[email protected]79540052012-10-19 23:15:26125 return (cls._git_base_calls(similarity, find_copies) +
[email protected]c1737d02013-05-29 14:17:28126 cls._git_upload_calls(private))
[email protected]a3353652011-11-30 14:26:57127
[email protected]0f58fa82012-11-05 01:45:20128 @classmethod
[email protected]615a2622013-05-03 13:20:14129 def _upload_no_rev_calls(cls, similarity, find_copies):
130 return (cls._git_base_calls(similarity, find_copies) +
131 cls._git_upload_no_rev_calls())
132
133 @classmethod
[email protected]0f58fa82012-11-05 01:45:20134 def _git_base_calls(cls, similarity, find_copies):
[email protected]53937ba2012-10-02 18:20:43135 if similarity is None:
136 similarity = '50'
[email protected]82b91cd2013-07-09 06:33:41137 similarity_call = ((['git', 'config', '--int', '--get',
[email protected]53937ba2012-10-02 18:20:43138 'branch.master.git-cl-similarity'],), '')
139 else:
[email protected]82b91cd2013-07-09 06:33:41140 similarity_call = ((['git', 'config', '--int',
[email protected]53937ba2012-10-02 18:20:43141 'branch.master.git-cl-similarity', similarity],), '')
[email protected]79540052012-10-19 23:15:26142
143 if find_copies is None:
144 find_copies = True
[email protected]82b91cd2013-07-09 06:33:41145 find_copies_call = ((['git', 'config', '--int', '--get',
[email protected]79540052012-10-19 23:15:26146 'branch.master.git-find-copies'],), '')
147 else:
148 val = str(int(find_copies))
[email protected]82b91cd2013-07-09 06:33:41149 find_copies_call = ((['git', 'config', '--int',
[email protected]79540052012-10-19 23:15:26150 'branch.master.git-find-copies', val],), '')
151
152 if find_copies:
[email protected]82b91cd2013-07-09 06:33:41153 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
[email protected]79540052012-10-19 23:15:26154 '--find-copies-harder', '-l100000', '-C'+similarity,
[email protected]5e07e062013-02-28 23:55:44155 'fake_ancestor_sha', 'HEAD'],), '+dat')
[email protected]79540052012-10-19 23:15:26156 else:
[email protected]82b91cd2013-07-09 06:33:41157 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
[email protected]5e07e062013-02-28 23:55:44158 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
[email protected]79540052012-10-19 23:15:26159
[email protected]ddd59412011-11-30 14:20:38160 return [
[email protected]87884cc2014-01-03 22:23:41161 ((['git', 'config', 'rietveld.autoupdate'],), ''),
[email protected]82b91cd2013-07-09 06:33:41162 ((['git', 'config', 'rietveld.server'],),
[email protected]f267b0e2013-05-02 09:11:43163 'codereview.example.com'),
[email protected]82b91cd2013-07-09 06:33:41164 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
[email protected]53937ba2012-10-02 18:20:43165 similarity_call,
[email protected]82b91cd2013-07-09 06:33:41166 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
[email protected]79540052012-10-19 23:15:26167 find_copies_call,
[email protected]82b91cd2013-07-09 06:33:41168 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
169 ((['git', 'config', 'branch.master.merge'],), 'master'),
170 ((['git', 'config', 'branch.master.remote'],), 'origin'),
[email protected]9e849272014-04-04 00:31:55171 ((['get_or_create_merge_base', 'master', 'master'],),
[email protected]f267b0e2013-05-02 09:11:43172 'fake_ancestor_sha'),
[email protected]eed4df32015-04-10 21:30:20173 ((['git', 'config', 'gerrit.host'],), ''),
[email protected]0f58fa82012-11-05 01:45:20174 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
[email protected]82b91cd2013-07-09 06:33:41175 ((['git', 'rev-parse', '--show-cdup'],), ''),
176 ((['git', 'rev-parse', 'HEAD'],), '12345'),
177 ((['git', 'diff', '--name-status', '--no-renames', '-r',
[email protected]f267b0e2013-05-02 09:11:43178 'fake_ancestor_sha...', '.'],),
[email protected]2e72bb12012-01-17 15:18:35179 'M\t.gitignore\n'),
[email protected]5df79ca2015-04-13 13:59:24180 ((['git', 'config', 'branch.master.rietveldissue'],), ''),
[email protected]82b91cd2013-07-09 06:33:41181 ((['git', 'config', 'branch.master.rietveldpatchset'],),
[email protected]f267b0e2013-05-02 09:11:43182 ''),
[email protected]82b91cd2013-07-09 06:33:41183 ((['git', 'log', '--pretty=format:%s%n%n%b',
[email protected]f267b0e2013-05-02 09:11:43184 'fake_ancestor_sha...'],),
[email protected]0f58fa82012-11-05 01:45:20185 'foo'),
[email protected]82b91cd2013-07-09 06:33:41186 ((['git', 'config', 'user.email'],), '[email protected]'),
[email protected]79540052012-10-19 23:15:26187 stat_call,
[email protected]82b91cd2013-07-09 06:33:41188 ((['git', 'log', '--pretty=format:%s\n\n%b',
[email protected]f267b0e2013-05-02 09:11:43189 'fake_ancestor_sha..HEAD'],),
[email protected]0f58fa82012-11-05 01:45:20190 'desc\n'),
[email protected]90752582014-01-14 21:04:50191 ((['git', 'config', 'rietveld.bug-prefix'],), ''),
[email protected]a3353652011-11-30 14:26:57192 ]
193
[email protected]0f58fa82012-11-05 01:45:20194 @classmethod
[email protected]615a2622013-05-03 13:20:14195 def _git_upload_no_rev_calls(cls):
196 return [
[email protected]82b91cd2013-07-09 06:33:41197 ((['git', 'config', 'core.editor'],), ''),
[email protected]615a2622013-05-03 13:20:14198 ]
199
200 @classmethod
[email protected]c1737d02013-05-29 14:17:28201 def _git_upload_calls(cls, private):
202 if private:
[email protected]99918ab2013-09-30 06:17:28203 cc_call = []
[email protected]c1737d02013-05-29 14:17:28204 private_call = []
205 else:
[email protected]99918ab2013-09-30 06:17:28206 cc_call = [((['git', 'config', 'rietveld.cc'],), '')]
[email protected]c1737d02013-05-29 14:17:28207 private_call = [
[email protected]82b91cd2013-07-09 06:33:41208 ((['git', 'config', 'rietveld.private'],), '')]
[email protected]c1737d02013-05-29 14:17:28209
[email protected]a3353652011-11-30 14:26:57210 return [
[email protected]82b91cd2013-07-09 06:33:41211 ((['git', 'config', 'core.editor'],), ''),
[email protected]99918ab2013-09-30 06:17:28212 ] + cc_call + private_call + [
[email protected]82b91cd2013-07-09 06:33:41213 ((['git', 'config', 'branch.master.base-url'],), ''),
[email protected]566a02a2014-08-22 01:34:13214 ((['git', 'config', 'rietveld.pending-ref-prefix'],), ''),
[email protected]82b91cd2013-07-09 06:33:41215 ((['git',
[email protected]05fb9112014-07-07 09:30:23216 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
217 (('', None), 0)),
[email protected]7a54e812014-02-11 19:57:22218 ((['git', 'rev-parse', '--show-cdup'],), ''),
[email protected]82b91cd2013-07-09 06:33:41219 ((['git', 'svn', 'info'],), ''),
[email protected]152cf832014-06-11 21:37:49220 ((['git', 'config', 'rietveld.project'],), ''),
[email protected]82b91cd2013-07-09 06:33:41221 ((['git',
[email protected]c1737d02013-05-29 14:17:28222 'config', 'branch.master.rietveldissue', '1'],), ''),
[email protected]82b91cd2013-07-09 06:33:41223 ((['git', 'config', 'branch.master.rietveldserver',
[email protected]c1737d02013-05-29 14:17:28224 'https://codereview.example.com'],), ''),
[email protected]82b91cd2013-07-09 06:33:41225 ((['git',
[email protected]c1737d02013-05-29 14:17:28226 'config', 'branch.master.rietveldpatchset', '2'],), ''),
[email protected]82b91cd2013-07-09 06:33:41227 ((['git', 'rev-parse', 'HEAD'],), 'hash'),
228 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'),
229 ((['git',
[email protected]c1737d02013-05-29 14:17:28230 'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
[email protected]5626a922015-02-26 14:03:30231 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''),
[email protected]ddd59412011-11-30 14:20:38232 ]
233
[email protected]0f58fa82012-11-05 01:45:20234 @staticmethod
235 def _git_sanity_checks(diff_base, working_branch):
236 fake_ancestor = 'fake_ancestor'
237 fake_cl = 'fake_cl_for_patch'
238 return [
239 # Calls to verify branch point is ancestor
[email protected]82b91cd2013-07-09 06:33:41240 ((['git',
[email protected]f267b0e2013-05-02 09:11:43241 'rev-parse', '--verify', diff_base],), fake_ancestor),
[email protected]82b91cd2013-07-09 06:33:41242 ((['git',
[email protected]f267b0e2013-05-02 09:11:43243 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor),
[email protected]82b91cd2013-07-09 06:33:41244 ((['git',
[email protected]f267b0e2013-05-02 09:11:43245 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl),
[email protected]0f58fa82012-11-05 01:45:20246 # Mock a config miss (error code 1)
[email protected]82b91cd2013-07-09 06:33:41247 ((['git',
[email protected]f267b0e2013-05-02 09:11:43248 'config', 'gitcl.remotebranch'],), (('', None), 1)),
[email protected]0f58fa82012-11-05 01:45:20249 # Call to GetRemoteBranch()
[email protected]82b91cd2013-07-09 06:33:41250 ((['git',
[email protected]f267b0e2013-05-02 09:11:43251 'config', 'branch.%s.merge' % working_branch],),
[email protected]0f58fa82012-11-05 01:45:20252 'refs/heads/master'),
[email protected]82b91cd2013-07-09 06:33:41253 ((['git',
[email protected]f267b0e2013-05-02 09:11:43254 'config', 'branch.%s.remote' % working_branch],), 'origin'),
[email protected]82b91cd2013-07-09 06:33:41255 ((['git', 'rev-list', '^' + fake_ancestor,
[email protected]0f58fa82012-11-05 01:45:20256 'refs/remotes/origin/master'],), ''),
257 ]
258
[email protected]2e72bb12012-01-17 15:18:35259 @classmethod
260 def _dcommit_calls_1(cls):
261 return [
[email protected]566a02a2014-08-22 01:34:13262 ((['git', 'config', 'rietveld.autoupdate'],),
263 ''),
264 ((['git', 'config', 'rietveld.pending-ref-prefix'],),
265 ''),
[email protected]82b91cd2013-07-09 06:33:41266 ((['git',
[email protected]05fb9112014-07-07 09:30:23267 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
[email protected]2e72bb12012-01-17 15:18:35268 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n'
269 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'),
270 None),
271 0)),
[email protected]82b91cd2013-07-09 06:33:41272 ((['git',
[email protected]f267b0e2013-05-02 09:11:43273 'config', 'rietveld.server'],), 'codereview.example.com'),
[email protected]82b91cd2013-07-09 06:33:41274 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
275 ((['git', 'config', '--int', '--get',
[email protected]53937ba2012-10-02 18:20:43276 'branch.working.git-cl-similarity'],), ''),
[email protected]82b91cd2013-07-09 06:33:41277 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
278 ((['git', 'config', '--int', '--get',
[email protected]79540052012-10-19 23:15:26279 'branch.working.git-find-copies'],), ''),
[email protected]82b91cd2013-07-09 06:33:41280 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
281 ((['git',
[email protected]f267b0e2013-05-02 09:11:43282 'config', 'branch.working.merge'],), 'refs/heads/master'),
[email protected]82b91cd2013-07-09 06:33:41283 ((['git', 'config', 'branch.working.remote'],), 'origin'),
[email protected]5724c962014-04-11 09:32:56284 ((['git', 'config', 'branch.working.merge'],),
285 'refs/heads/master'),
286 ((['git', 'config', 'branch.working.remote'],), 'origin'),
[email protected]82b91cd2013-07-09 06:33:41287 ((['git', 'rev-list', '--merges',
[email protected]e84b7542012-06-15 21:26:58288 '--grep=^SVN changes up to revision [0-9]*$',
[email protected]9bb85e22012-06-13 20:28:23289 'refs/remotes/origin/master^!'],), ''),
[email protected]82b91cd2013-07-09 06:33:41290 ((['git', 'rev-list', '^refs/heads/working',
[email protected]2e72bb12012-01-17 15:18:35291 'refs/remotes/origin/master'],),
292 ''),
[email protected]82b91cd2013-07-09 06:33:41293 ((['git',
[email protected]f267b0e2013-05-02 09:11:43294 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],),
[email protected]2e72bb12012-01-17 15:18:35295 '3fc18b62c4966193eb435baabe2d18a3810ec82e'),
[email protected]82b91cd2013-07-09 06:33:41296 ((['git',
[email protected]f267b0e2013-05-02 09:11:43297 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e',
[email protected]2e72bb12012-01-17 15:18:35298 'refs/remotes/origin/master'],), ''),
[email protected]82b91cd2013-07-09 06:33:41299 ((['git',
[email protected]f267b0e2013-05-02 09:11:43300 'merge-base', 'refs/remotes/origin/master', 'HEAD'],),
[email protected]0f58fa82012-11-05 01:45:20301 'fake_ancestor_sha'),
[email protected]2e72bb12012-01-17 15:18:35302 ]
303
304 @classmethod
305 def _dcommit_calls_normal(cls):
306 return [
[email protected]82b91cd2013-07-09 06:33:41307 ((['git', 'rev-parse', '--show-cdup'],), ''),
308 ((['git', 'rev-parse', 'HEAD'],),
[email protected]2e72bb12012-01-17 15:18:35309 '00ff397798ea57439712ed7e04ab96e13969ef40'),
[email protected]82b91cd2013-07-09 06:33:41310 ((['git',
[email protected]9249f642013-06-03 21:36:18311 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...',
[email protected]2e72bb12012-01-17 15:18:35312 '.'],),
313 'M\tPRESUBMIT.py'),
[email protected]82b91cd2013-07-09 06:33:41314 ((['git',
[email protected]f267b0e2013-05-02 09:11:43315 'config', 'branch.working.rietveldissue'],), '12345'),
[email protected]82b91cd2013-07-09 06:33:41316 ((['git',
[email protected]f267b0e2013-05-02 09:11:43317 'config', 'branch.working.rietveldpatchset'],), '31137'),
[email protected]82b91cd2013-07-09 06:33:41318 ((['git', 'config', 'branch.working.rietveldserver'],),
[email protected]2e72bb12012-01-17 15:18:35319 'codereview.example.com'),
[email protected]82b91cd2013-07-09 06:33:41320 ((['git', 'config', 'user.email'],), '[email protected]'),
321 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
[email protected]2e72bb12012-01-17 15:18:35322 ]
323
324 @classmethod
325 def _dcommit_calls_bypassed(cls):
326 return [
[email protected]82b91cd2013-07-09 06:33:41327 ((['git',
[email protected]f267b0e2013-05-02 09:11:43328 'config', 'branch.working.rietveldissue'],), '12345'),
[email protected]82b91cd2013-07-09 06:33:41329 ((['git', 'config', 'branch.working.rietveldserver'],),
[email protected]2e72bb12012-01-17 15:18:35330 'codereview.example.com'),
[email protected]3ec0d542014-01-14 20:00:03331 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
[email protected]2e72bb12012-01-17 15:18:35332 (('GitClHooksBypassedCommit',
333 'Issue https://codereview.example.com/12345 bypassed hook when '
[email protected]3ec0d542014-01-14 20:00:03334 'committing (tree status was "unset")'), None),
[email protected]2e72bb12012-01-17 15:18:35335 ]
336
337 @classmethod
[email protected]7a54e812014-02-11 19:57:22338 def _dcommit_calls_3(cls):
339 return [
[email protected]82b91cd2013-07-09 06:33:41340 ((['git',
[email protected]f267b0e2013-05-02 09:11:43341 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
[email protected]0f58fa82012-11-05 01:45:20342 '-l100000', '-C50', 'fake_ancestor_sha',
[email protected]53937ba2012-10-02 18:20:43343 'refs/heads/working'],),
[email protected]2e72bb12012-01-17 15:18:35344 (' PRESUBMIT.py | 2 +-\n'
345 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')),
[email protected]82b91cd2013-07-09 06:33:41346 ((['git', 'show-ref', '--quiet', '--verify',
[email protected]2e72bb12012-01-17 15:18:35347 'refs/heads/git-cl-commit'],),
348 (('', None), 0)),
[email protected]82b91cd2013-07-09 06:33:41349 ((['git', 'branch', '-D', 'git-cl-commit'],), ''),
350 ((['git', 'show-ref', '--quiet', '--verify',
[email protected]9bb85e22012-06-13 20:28:23351 'refs/heads/git-cl-cherry-pick'],), ''),
[email protected]7a54e812014-02-11 19:57:22352 ((['git', 'rev-parse', '--show-cdup'],), '\n'),
[email protected]82b91cd2013-07-09 06:33:41353 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''),
354 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''),
355 ((['git', 'commit', '-m',
[email protected]e52678e2013-04-26 18:34:44356 'Issue: 12345\n\[email protected]\n\n'
[email protected]78936cb2013-04-11 00:17:52357 'Review URL: https://codereview.example.com/12345'],),
[email protected]2e72bb12012-01-17 15:18:35358 ''),
[email protected]6abc6522014-12-02 07:34:49359 ((['git', 'config', 'rietveld.force-https-commit-url'],), ''),
[email protected]82b91cd2013-07-09 06:33:41360 ((['git',
[email protected]f267b0e2013-05-02 09:11:43361 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],),
[email protected]53937ba2012-10-02 18:20:43362 (('', None), 0)),
[email protected]82b91cd2013-07-09 06:33:41363 ((['git', 'checkout', '-q', 'working'],), ''),
364 ((['git', 'branch', '-D', 'git-cl-commit'],), ''),
[email protected]7a54e812014-02-11 19:57:22365 ]
[email protected]2e72bb12012-01-17 15:18:35366
[email protected]ddd59412011-11-30 14:20:38367 @staticmethod
[email protected]c1737d02013-05-29 14:17:28368 def _cmd_line(description, args, similarity, find_copies, private):
[email protected]ddd59412011-11-30 14:20:38369 """Returns the upload command line passed to upload.RealMain()."""
[email protected]ddd59412011-11-30 14:20:38370 return [
371 'upload', '--assume_yes', '--server',
[email protected]eb5edbc2012-01-16 17:03:28372 'https://codereview.example.com',
[email protected]71e12a92012-02-14 02:34:15373 '--message', description
[email protected]ddd59412011-11-30 14:20:38374 ] + args + [
375 '--cc', '[email protected]',
[email protected]c1737d02013-05-29 14:17:28376 ] + (['--private'] if private else []) + [
[email protected]79540052012-10-19 23:15:26377 '--git_similarity', similarity or '50'
378 ] + (['--git_no_find_copies'] if find_copies == False else []) + [
[email protected]5e07e062013-02-28 23:55:44379 'fake_ancestor_sha', 'HEAD'
[email protected]ddd59412011-11-30 14:20:38380 ]
381
382 def _run_reviewer_test(
383 self,
384 upload_args,
385 expected_description,
386 returned_description,
387 final_description,
[email protected]c1737d02013-05-29 14:17:28388 reviewers,
389 private=False):
[email protected]ddd59412011-11-30 14:20:38390 """Generic reviewer test framework."""
[email protected]53937ba2012-10-02 18:20:43391 try:
392 similarity = upload_args[upload_args.index('--similarity')+1]
393 except ValueError:
394 similarity = None
[email protected]79540052012-10-19 23:15:26395
396 if '--find-copies' in upload_args:
397 find_copies = True
398 elif '--no-find-copies' in upload_args:
399 find_copies = False
400 else:
401 find_copies = None
402
[email protected]c1737d02013-05-29 14:17:28403 private = '--private' in upload_args
404
405 self.calls = self._upload_calls(similarity, find_copies, private)
[email protected]87884cc2014-01-03 22:23:41406
[email protected]615a2622013-05-03 13:20:14407 def RunEditor(desc, _, **kwargs):
[email protected]ddd59412011-11-30 14:20:38408 self.assertEquals(
409 '# Enter a description of the change.\n'
[email protected]104b2db2013-04-18 12:58:40410 '# This will be displayed on the codereview site.\n'
[email protected]63a4d7f2013-05-31 02:22:45411 '# The first line will also be used as the subject of the review.\n'
[email protected]bd1073e2013-06-01 00:34:38412 '#--------------------This line is 72 characters long'
413 '--------------------\n' +
[email protected]ddd59412011-11-30 14:20:38414 expected_description,
415 desc)
416 return returned_description
417 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
[email protected]87884cc2014-01-03 22:23:41418
[email protected]ddd59412011-11-30 14:20:38419 def check_upload(args):
[email protected]79540052012-10-19 23:15:26420 cmd_line = self._cmd_line(final_description, reviewers, similarity,
[email protected]c1737d02013-05-29 14:17:28421 find_copies, private)
[email protected]53937ba2012-10-02 18:20:43422 self.assertEquals(cmd_line, args)
[email protected]ddd59412011-11-30 14:20:38423 return 1, 2
424 self.mock(git_cl.upload, 'RealMain', check_upload)
[email protected]87884cc2014-01-03 22:23:41425
[email protected]ddd59412011-11-30 14:20:38426 git_cl.main(['upload'] + upload_args)
427
428 def test_no_reviewer(self):
429 self._run_reviewer_test(
430 [],
[email protected]78936cb2013-04-11 00:17:52431 'desc\n\nBUG=',
432 '# Blah blah comment.\ndesc\n\nBUG=',
433 'desc\n\nBUG=',
[email protected]ddd59412011-11-30 14:20:38434 [])
435
[email protected]53937ba2012-10-02 18:20:43436 def test_keep_similarity(self):
437 self._run_reviewer_test(
438 ['--similarity', '70'],
[email protected]78936cb2013-04-11 00:17:52439 'desc\n\nBUG=',
440 '# Blah blah comment.\ndesc\n\nBUG=',
441 'desc\n\nBUG=',
[email protected]53937ba2012-10-02 18:20:43442 [])
443
[email protected]79540052012-10-19 23:15:26444 def test_keep_find_copies(self):
445 self._run_reviewer_test(
446 ['--no-find-copies'],
[email protected]78936cb2013-04-11 00:17:52447 'desc\n\nBUG=',
[email protected]79540052012-10-19 23:15:26448 '# Blah blah comment.\ndesc\n\nBUG=\n',
[email protected]78936cb2013-04-11 00:17:52449 'desc\n\nBUG=',
[email protected]79540052012-10-19 23:15:26450 [])
451
[email protected]c1737d02013-05-29 14:17:28452 def test_private(self):
453 self._run_reviewer_test(
454 ['--private'],
455 'desc\n\nBUG=',
456 '# Blah blah comment.\ndesc\n\nBUG=\n',
457 'desc\n\nBUG=',
458 [])
459
[email protected]ddd59412011-11-30 14:20:38460 def test_reviewers_cmd_line(self):
461 # Reviewer is passed as-is
[email protected]78936cb2013-04-11 00:17:52462 description = 'desc\n\[email protected]\nBUG='
[email protected]ddd59412011-11-30 14:20:38463 self._run_reviewer_test(
464 ['-r' '[email protected]'],
465 description,
466 '\n%s\n' % description,
467 description,
[email protected]78936cb2013-04-11 00:17:52468 ['[email protected]'])
[email protected]ddd59412011-11-30 14:20:38469
470 def test_reviewer_tbr_overriden(self):
471 # Reviewer is overriden with TBR
472 # Also verifies the regexp work without a trailing LF
[email protected]78936cb2013-04-11 00:17:52473 description = 'Foo Bar\n\[email protected]'
[email protected]ddd59412011-11-30 14:20:38474 self._run_reviewer_test(
475 ['-r' '[email protected]'],
[email protected]78936cb2013-04-11 00:17:52476 'desc\n\[email protected]\nBUG=',
[email protected]ddd59412011-11-30 14:20:38477 description.strip('\n'),
478 description,
[email protected]78936cb2013-04-11 00:17:52479 ['[email protected]'])
[email protected]ddd59412011-11-30 14:20:38480
481 def test_reviewer_multiple(self):
482 # Handles multiple R= or TBR= lines.
483 description = (
[email protected]78936cb2013-04-11 00:17:52484 'Foo Bar\[email protected]\nBUG=\[email protected]')
[email protected]ddd59412011-11-30 14:20:38485 self._run_reviewer_test(
486 [],
[email protected]78936cb2013-04-11 00:17:52487 'desc\n\nBUG=',
[email protected]ddd59412011-11-30 14:20:38488 description,
489 description,
[email protected]78936cb2013-04-11 00:17:52490 ['[email protected],[email protected]'])
[email protected]ddd59412011-11-30 14:20:38491
[email protected]a3353652011-11-30 14:26:57492 def test_reviewer_send_mail(self):
493 # --send-mail can be used without -r if R= is used
[email protected]78936cb2013-04-11 00:17:52494 description = 'Foo Bar\[email protected]'
[email protected]a3353652011-11-30 14:26:57495 self._run_reviewer_test(
496 ['--send-mail'],
[email protected]78936cb2013-04-11 00:17:52497 'desc\n\nBUG=',
[email protected]a3353652011-11-30 14:26:57498 description.strip('\n'),
499 description,
[email protected]78936cb2013-04-11 00:17:52500 ['[email protected]', '--send_mail'])
[email protected]a3353652011-11-30 14:26:57501
502 def test_reviewer_send_mail_no_rev(self):
503 # Fails without a reviewer.
[email protected]2e23ce32013-05-07 12:42:28504 stdout = StringIO.StringIO()
505 stderr = StringIO.StringIO()
[email protected]a3353652011-11-30 14:26:57506 try:
[email protected]615a2622013-05-03 13:20:14507 self.calls = self._upload_no_rev_calls(None, None)
508 def RunEditor(desc, _, **kwargs):
[email protected]a3353652011-11-30 14:26:57509 return desc
510 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
[email protected]2e23ce32013-05-07 12:42:28511 self.mock(sys, 'stdout', stdout)
512 self.mock(sys, 'stderr', stderr)
[email protected]a3353652011-11-30 14:26:57513 git_cl.main(['upload', '--send-mail'])
514 self.fail()
515 except SystemExit:
[email protected]2e23ce32013-05-07 12:42:28516 self.assertEqual(
517 'Using 50% similarity for rename/copy detection. Override with '
518 '--similarity.\n',
519 stdout.getvalue())
520 self.assertEqual(
521 'Must specify reviewers to send email.\n', stderr.getvalue())
[email protected]a3353652011-11-30 14:26:57522
[email protected]2e72bb12012-01-17 15:18:35523 def test_dcommit(self):
524 self.calls = (
525 self._dcommit_calls_1() +
[email protected]0f58fa82012-11-05 01:45:20526 self._git_sanity_checks('fake_ancestor_sha', 'working') +
[email protected]2e72bb12012-01-17 15:18:35527 self._dcommit_calls_normal() +
[email protected]7a54e812014-02-11 19:57:22528 self._dcommit_calls_3())
[email protected]2e72bb12012-01-17 15:18:35529 git_cl.main(['dcommit'])
530
531 def test_dcommit_bypass_hooks(self):
532 self.calls = (
533 self._dcommit_calls_1() +
534 self._dcommit_calls_bypassed() +
[email protected]7a54e812014-02-11 19:57:22535 self._dcommit_calls_3())
[email protected]2e72bb12012-01-17 15:18:35536 git_cl.main(['dcommit', '--bypass-hooks'])
537
[email protected]ddd59412011-11-30 14:20:38538
[email protected]0f58fa82012-11-05 01:45:20539 @classmethod
540 def _gerrit_base_calls(cls):
[email protected]e8077812012-02-03 03:41:46541 return [
[email protected]87884cc2014-01-03 22:23:41542 ((['git', 'config', 'rietveld.autoupdate'],),
543 ''),
[email protected]82b91cd2013-07-09 06:33:41544 ((['git',
[email protected]f267b0e2013-05-02 09:11:43545 'config', 'rietveld.server'],), 'codereview.example.com'),
[email protected]82b91cd2013-07-09 06:33:41546 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
547 ((['git', 'config', '--int', '--get',
[email protected]53937ba2012-10-02 18:20:43548 'branch.master.git-cl-similarity'],), ''),
[email protected]82b91cd2013-07-09 06:33:41549 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
550 ((['git', 'config', '--int', '--get',
[email protected]79540052012-10-19 23:15:26551 'branch.master.git-find-copies'],), ''),
[email protected]82b91cd2013-07-09 06:33:41552 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
553 ((['git', 'config', 'branch.master.merge'],), 'master'),
554 ((['git', 'config', 'branch.master.remote'],), 'origin'),
[email protected]9e849272014-04-04 00:31:55555 ((['get_or_create_merge_base', 'master', 'master'],),
556 'fake_ancestor_sha'),
[email protected]eed4df32015-04-10 21:30:20557 ((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'),
[email protected]0f58fa82012-11-05 01:45:20558 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
[email protected]82b91cd2013-07-09 06:33:41559 ((['git', 'rev-parse', '--show-cdup'],), ''),
560 ((['git', 'rev-parse', 'HEAD'],), '12345'),
561 ((['git',
[email protected]9249f642013-06-03 21:36:18562 'diff', '--name-status', '--no-renames', '-r',
563 'fake_ancestor_sha...', '.'],),
[email protected]e8077812012-02-03 03:41:46564 'M\t.gitignore\n'),
[email protected]82b91cd2013-07-09 06:33:41565 ((['git', 'config', 'branch.master.rietveldissue'],), ''),
566 ((['git',
[email protected]f267b0e2013-05-02 09:11:43567 'config', 'branch.master.rietveldpatchset'],), ''),
[email protected]82b91cd2013-07-09 06:33:41568 ((['git',
[email protected]f267b0e2013-05-02 09:11:43569 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
[email protected]0f58fa82012-11-05 01:45:20570 'foo'),
[email protected]82b91cd2013-07-09 06:33:41571 ((['git', 'config', 'user.email'],), '[email protected]'),
572 ((['git',
[email protected]f267b0e2013-05-02 09:11:43573 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
[email protected]5e07e062013-02-28 23:55:44574 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
[email protected]e8077812012-02-03 03:41:46575 '+dat'),
576 ]
577
578 @staticmethod
[email protected]27386dd2015-02-16 10:45:39579 def _gerrit_upload_calls(description, reviewers, squash):
[email protected]e8077812012-02-03 03:41:46580 calls = [
[email protected]82b91cd2013-07-09 06:33:41581 ((['git', 'log', '--pretty=format:%s\n\n%b',
[email protected]5e07e062013-02-28 23:55:44582 'fake_ancestor_sha..HEAD'],),
[email protected]aebe87f2012-10-22 20:34:21583 description)
584 ]
585 if git_cl.CHANGE_ID not in description:
586 calls += [
[email protected]82b91cd2013-07-09 06:33:41587 ((['git', 'log', '--pretty=format:%s\n\n%b',
[email protected]5e07e062013-02-28 23:55:44588 'fake_ancestor_sha..HEAD'],),
[email protected]aebe87f2012-10-22 20:34:21589 description),
[email protected]82b91cd2013-07-09 06:33:41590 ((['git', 'commit', '--amend', '-m', description],),
[email protected]aebe87f2012-10-22 20:34:21591 ''),
[email protected]82b91cd2013-07-09 06:33:41592 ((['git', 'log', '--pretty=format:%s\n\n%b',
[email protected]5e07e062013-02-28 23:55:44593 'fake_ancestor_sha..HEAD'],),
[email protected]aebe87f2012-10-22 20:34:21594 description)
595 ]
[email protected]27386dd2015-02-16 10:45:39596 if squash:
597 ref_to_push = 'abcdef0123456789'
598 calls += [
599 ((['git', 'show', '--format=%s\n\n%b', '-s',
600 'refs/heads/git_cl_uploads/master'],),
601 (description, 0)),
602 ((['git', 'config', 'branch.master.merge'],),
603 'refs/heads/master'),
604 ((['git', 'config', 'branch.master.remote'],),
605 'origin'),
606 ((['get_or_create_merge_base', 'master', 'master'],),
607 'origin/master'),
608 ((['git', 'rev-parse', 'HEAD:'],),
609 '0123456789abcdef'),
610 ((['git', 'commit-tree', '0123456789abcdef', '-p',
611 'origin/master', '-m', 'd'],),
612 ref_to_push),
613 ]
614 else:
615 ref_to_push = 'HEAD'
616
[email protected]aebe87f2012-10-22 20:34:21617 calls += [
[email protected]27386dd2015-02-16 10:45:39618 ((['git', 'rev-list', 'origin/master..' + ref_to_push],), ''),
[email protected]82b91cd2013-07-09 06:33:41619 ((['git', 'config', 'rietveld.cc'],), '')
[email protected]e8077812012-02-03 03:41:46620 ]
[email protected]19bbfa22012-02-03 16:18:11621 receive_pack = '--receive-pack=git receive-pack '
[email protected]e8077812012-02-03 03:41:46622 receive_pack += '[email protected]' # from watch list
623 if reviewers:
624 receive_pack += ' '
[email protected]78936cb2013-04-11 00:17:52625 receive_pack += ' '.join(
626 '--reviewer=' + email for email in sorted(reviewers))
[email protected]19bbfa22012-02-03 16:18:11627 receive_pack += ''
[email protected]e8077812012-02-03 03:41:46628 calls += [
[email protected]82b91cd2013-07-09 06:33:41629 ((['git',
[email protected]27386dd2015-02-16 10:45:39630 'push', receive_pack, 'origin', ref_to_push + ':refs/for/master'],),
[email protected]e8077812012-02-03 03:41:46631 '')
632 ]
[email protected]27386dd2015-02-16 10:45:39633 if squash:
634 calls += [
635 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'),
636 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789',
637 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],),
638 '')
639 ]
640
[email protected]e8077812012-02-03 03:41:46641 return calls
642
[email protected]aebe87f2012-10-22 20:34:21643 def _run_gerrit_upload_test(
[email protected]e8077812012-02-03 03:41:46644 self,
645 upload_args,
646 description,
[email protected]27386dd2015-02-16 10:45:39647 reviewers,
648 squash=False):
[email protected]aebe87f2012-10-22 20:34:21649 """Generic gerrit upload test framework."""
[email protected]e8077812012-02-03 03:41:46650 self.calls = self._gerrit_base_calls()
[email protected]27386dd2015-02-16 10:45:39651 self.calls += self._gerrit_upload_calls(description, reviewers, squash)
[email protected]e8077812012-02-03 03:41:46652 git_cl.main(['upload'] + upload_args)
653
[email protected]aebe87f2012-10-22 20:34:21654 def test_gerrit_upload_without_change_id(self):
655 self._run_gerrit_upload_test(
[email protected]e8077812012-02-03 03:41:46656 [],
[email protected]35d1a842012-07-27 00:20:43657 'desc\n\nBUG=\n',
[email protected]e8077812012-02-03 03:41:46658 [])
659
[email protected]aebe87f2012-10-22 20:34:21660 def test_gerrit_no_reviewer(self):
661 self._run_gerrit_upload_test(
662 [],
663 'desc\n\nBUG=\nChange-Id:123456789\n',
664 [])
665
[email protected]e8077812012-02-03 03:41:46666 def test_gerrit_reviewers_cmd_line(self):
[email protected]aebe87f2012-10-22 20:34:21667 self._run_gerrit_upload_test(
[email protected]e8077812012-02-03 03:41:46668 ['-r', '[email protected]'],
[email protected]aebe87f2012-10-22 20:34:21669 'desc\n\nBUG=\nChange-Id:123456789',
[email protected]e8077812012-02-03 03:41:46670 ['[email protected]'])
671
672 def test_gerrit_reviewer_multiple(self):
[email protected]aebe87f2012-10-22 20:34:21673 self._run_gerrit_upload_test(
[email protected]e8077812012-02-03 03:41:46674 [],
[email protected]aebe87f2012-10-22 20:34:21675 'desc\[email protected]\nBUG=\[email protected]\n'
676 'Change-Id:123456789\n',
[email protected]e8077812012-02-03 03:41:46677 ['[email protected]', '[email protected]'])
678
[email protected]27386dd2015-02-16 10:45:39679 def test_gerrit_upload_squash(self):
680 self._run_gerrit_upload_test(
681 ['--squash'],
682 'desc\n\nBUG=\nChange-Id:123456789\n',
683 [],
684 squash=True)
[email protected]e8077812012-02-03 03:41:46685
[email protected]78c4b982012-02-14 02:20:26686 def test_config_gerrit_download_hook(self):
687 self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock)
688 def ParseCodereviewSettingsContent(content):
689 keyvals = {}
690 keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org'
691 keyvals['GERRIT_HOST'] = 'gerrit.chromium.org'
692 keyvals['GERRIT_PORT'] = '29418'
693 return keyvals
694 self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent',
695 ParseCodereviewSettingsContent)
696 self.mock(git_cl.os, 'access', self._mocked_call)
697 self.mock(git_cl.os, 'chmod', self._mocked_call)
[email protected]91655502012-05-25 01:46:07698 src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src')
[email protected]78c4b982012-02-14 02:20:26699 def AbsPath(path):
[email protected]91655502012-05-25 01:46:07700 if not path.startswith(os.path.sep):
701 return os.path.join(src_dir, path)
[email protected]78c4b982012-02-14 02:20:26702 return path
703 self.mock(git_cl.os.path, 'abspath', AbsPath)
[email protected]91655502012-05-25 01:46:07704 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg')
[email protected]78c4b982012-02-14 02:20:26705 def Exists(path):
[email protected]91655502012-05-25 01:46:07706 if path == commit_msg_path:
[email protected]78c4b982012-02-14 02:20:26707 return False
708 # others paths, such as /usr/share/locale/....
709 return True
710 self.mock(git_cl.os.path, 'exists', Exists)
[email protected]426f69b2012-08-02 23:41:49711 self.mock(git_cl, 'urlretrieve', self._mocked_call)
[email protected]712d6102013-11-27 00:52:58712 self.mock(git_cl, 'hasSheBang', self._mocked_call)
[email protected]78c4b982012-02-14 02:20:26713 self.calls = [
[email protected]87884cc2014-01-03 22:23:41714 ((['git', 'config', 'rietveld.autoupdate'],),
715 ''),
[email protected]82b91cd2013-07-09 06:33:41716 ((['git', 'config', 'rietveld.server',
[email protected]f267b0e2013-05-02 09:11:43717 'gerrit.chromium.org'],), ''),
[email protected]82b91cd2013-07-09 06:33:41718 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''),
719 ((['git', 'config', '--unset-all',
[email protected]c1737d02013-05-29 14:17:28720 'rietveld.private'],), ''),
[email protected]82b91cd2013-07-09 06:33:41721 ((['git', 'config', '--unset-all',
[email protected]f267b0e2013-05-02 09:11:43722 'rietveld.tree-status-url'],), ''),
[email protected]82b91cd2013-07-09 06:33:41723 ((['git', 'config', '--unset-all',
[email protected]f267b0e2013-05-02 09:11:43724 'rietveld.viewvc-url'],), ''),
[email protected]90752582014-01-14 21:04:50725 ((['git', 'config', '--unset-all',
726 'rietveld.bug-prefix'],), ''),
[email protected]44202a22014-03-11 19:22:18727 ((['git', 'config', '--unset-all',
728 'rietveld.cpplint-regex'],), ''),
729 ((['git', 'config', '--unset-all',
[email protected]6abc6522014-12-02 07:34:49730 'rietveld.force-https-commit-url'],), ''),
731 ((['git', 'config', '--unset-all',
[email protected]44202a22014-03-11 19:22:18732 'rietveld.cpplint-ignore-regex'],), ''),
[email protected]152cf832014-06-11 21:37:49733 ((['git', 'config', '--unset-all',
734 'rietveld.project'],), ''),
[email protected]566a02a2014-08-22 01:34:13735 ((['git', 'config', '--unset-all',
736 'rietveld.pending-ref-prefix'],), ''),
[email protected]5626a922015-02-26 14:03:30737 ((['git', 'config', '--unset-all',
738 'rietveld.run-post-upload-hook'],), ''),
[email protected]82b91cd2013-07-09 06:33:41739 ((['git', 'config', 'gerrit.host',
[email protected]f267b0e2013-05-02 09:11:43740 'gerrit.chromium.org'],), ''),
[email protected]78c4b982012-02-14 02:20:26741 # DownloadHooks(False)
[email protected]82b91cd2013-07-09 06:33:41742 ((['git', 'config', 'gerrit.host'],),
[email protected]f267b0e2013-05-02 09:11:43743 'gerrit.chromium.org'),
[email protected]82b91cd2013-07-09 06:33:41744 ((['git', 'rev-parse', '--show-cdup'],), ''),
[email protected]91655502012-05-25 01:46:07745 ((commit_msg_path, os.X_OK,), False),
[email protected]712d6102013-11-27 00:52:58746 (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg',
[email protected]91655502012-05-25 01:46:07747 commit_msg_path,), ''),
[email protected]712d6102013-11-27 00:52:58748 ((commit_msg_path,), True),
[email protected]91655502012-05-25 01:46:07749 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
[email protected]78c4b982012-02-14 02:20:26750 # GetCodereviewSettingsInteractively
[email protected]82b91cd2013-07-09 06:33:41751 ((['git', 'config', 'rietveld.server'],),
[email protected]f267b0e2013-05-02 09:11:43752 'gerrit.chromium.org'),
[email protected]78c4b982012-02-14 02:20:26753 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
754 ''),
[email protected]82b91cd2013-07-09 06:33:41755 ((['git', 'config', 'rietveld.cc'],), ''),
[email protected]78c4b982012-02-14 02:20:26756 (('CC list:',), ''),
[email protected]82b91cd2013-07-09 06:33:41757 ((['git', 'config', 'rietveld.private'],), ''),
[email protected]c1737d02013-05-29 14:17:28758 (('Private flag (rietveld only):',), ''),
[email protected]82b91cd2013-07-09 06:33:41759 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
[email protected]78c4b982012-02-14 02:20:26760 (('Tree status URL:',), ''),
[email protected]82b91cd2013-07-09 06:33:41761 ((['git', 'config', 'rietveld.viewvc-url'],), ''),
[email protected]78c4b982012-02-14 02:20:26762 (('ViewVC URL:',), ''),
763 # DownloadHooks(True)
[email protected]90752582014-01-14 21:04:50764 ((['git', 'config', 'rietveld.bug-prefix'],), ''),
765 (('Bug Prefix:',), ''),
[email protected]5626a922015-02-26 14:03:30766 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''),
767 (('Run Post Upload Hook:',), ''),
[email protected]91655502012-05-25 01:46:07768 ((commit_msg_path, os.X_OK,), True),
[email protected]78c4b982012-02-14 02:20:26769 ]
770 git_cl.main(['config'])
771
[email protected]78936cb2013-04-11 00:17:52772 def test_update_reviewers(self):
773 data = [
774 ('foo', [], 'foo'),
[email protected]42c20792013-09-12 17:34:49775 ('foo\nR=xx', [], 'foo\nR=xx'),
776 ('foo\nTBR=xx', [], 'foo\nTBR=xx'),
[email protected]78936cb2013-04-11 00:17:52777 ('foo', ['a@c'], 'foo\n\nR=a@c'),
[email protected]42c20792013-09-12 17:34:49778 ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'),
779 ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'),
780 ('foo\nTBR=xx\nR=yy', ['a@c'], 'foo\n\nR=a@c, yy\nTBR=xx'),
[email protected]78936cb2013-04-11 00:17:52781 ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'),
[email protected]42c20792013-09-12 17:34:49782 ('foo\nR=xx\nTBR=yy\nR=bar', ['a@c'], 'foo\n\nR=a@c, xx, bar\nTBR=yy'),
[email protected]78936cb2013-04-11 00:17:52783 ('foo', ['a@c', 'b@c'], 'foo\n\nR=a@c, b@c'),
[email protected]c6f60e82013-04-19 17:01:57784 ('foo\nBar\n\nR=\nBUG=', ['c@c'], 'foo\nBar\n\nR=c@c\nBUG='),
785 ('foo\nBar\n\nR=\nBUG=\nR=', ['c@c'], 'foo\nBar\n\nR=c@c\nBUG='),
786 # Same as the line before, but full of whitespaces.
787 (
788 'foo\nBar\n\n R = \n BUG = \n R = ', ['c@c'],
789 'foo\nBar\n\nR=c@c\n BUG =',
790 ),
791 # Whitespaces aren't interpreted as new lines.
792 ('foo BUG=allo R=joe ', ['c@c'], 'foo BUG=allo R=joe\n\nR=c@c'),
[email protected]78936cb2013-04-11 00:17:52793 ]
[email protected]c6f60e82013-04-19 17:01:57794 expected = [i[2] for i in data]
795 actual = []
796 for orig, reviewers, _expected in data:
[email protected]78936cb2013-04-11 00:17:52797 obj = git_cl.ChangeDescription(orig)
798 obj.update_reviewers(reviewers)
[email protected]c6f60e82013-04-19 17:01:57799 actual.append(obj.description)
800 self.assertEqual(expected, actual)
[email protected]78936cb2013-04-11 00:17:52801
[email protected]455dc922015-01-26 20:15:50802 def test_get_target_ref(self):
803 # Check remote or remote branch not present.
804 self.assertEqual(None, git_cl.GetTargetRef('origin', None, 'master', None))
805 self.assertEqual(None, git_cl.GetTargetRef(None,
806 'refs/remotes/origin/master',
807 'master', None))
[email protected]27386dd2015-02-16 10:45:39808
[email protected]455dc922015-01-26 20:15:50809 # Check default target refs for branches.
810 self.assertEqual('refs/heads/master',
811 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master',
812 None, None))
813 self.assertEqual('refs/heads/master',
814 git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkgr',
815 None, None))
816 self.assertEqual('refs/heads/master',
817 git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkcr',
818 None, None))
819 self.assertEqual('refs/branch-heads/123',
820 git_cl.GetTargetRef('origin',
821 'refs/remotes/branch-heads/123',
822 None, None))
823 self.assertEqual('refs/diff/test',
824 git_cl.GetTargetRef('origin',
825 'refs/remotes/origin/refs/diff/test',
826 None, None))
[email protected]c68112d2015-03-03 12:48:06827 self.assertEqual('refs/heads/chrome/m42',
828 git_cl.GetTargetRef('origin',
829 'refs/remotes/origin/chrome/m42',
830 None, None))
[email protected]455dc922015-01-26 20:15:50831
832 # Check target refs for user-specified target branch.
833 for branch in ('branch-heads/123', 'remotes/branch-heads/123',
834 'refs/remotes/branch-heads/123'):
835 self.assertEqual('refs/branch-heads/123',
836 git_cl.GetTargetRef('origin',
837 'refs/remotes/origin/master',
838 branch, None))
839 for branch in ('origin/master', 'remotes/origin/master',
840 'refs/remotes/origin/master'):
841 self.assertEqual('refs/heads/master',
842 git_cl.GetTargetRef('origin',
843 'refs/remotes/branch-heads/123',
844 branch, None))
845 for branch in ('master', 'heads/master', 'refs/heads/master'):
846 self.assertEqual('refs/heads/master',
847 git_cl.GetTargetRef('origin',
848 'refs/remotes/branch-heads/123',
849 branch, None))
850
851 # Check target refs for pending prefix.
852 self.assertEqual('prefix/heads/master',
853 git_cl.GetTargetRef('origin', 'refs/remotes/origin/master',
854 None, 'prefix/'))
855
856
[email protected]ddd59412011-11-30 14:20:38857if __name__ == '__main__':
[email protected]78936cb2013-04-11 00:17:52858 git_cl.logging.basicConfig(
859 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
[email protected]ddd59412011-11-30 14:20:38860 unittest.main()