maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
maruel@chromium.org | eb5edbc | 2012-01-16 17:03:28 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 3 | # 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 | |
Andrii Shyshkalov | cd6a936 | 2016-12-07 12:04:12 +0100 | [diff] [blame] | 8 | import contextlib |
Andrii Shyshkalov | d8aa49f | 2017-03-17 16:05:49 +0100 | [diff] [blame] | 9 | import datetime |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 10 | import json |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 11 | import logging |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 12 | import os |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 13 | import StringIO |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 14 | import sys |
Aaron Gable | 9a03ae0 | 2017-11-03 11:31:07 -0700 | [diff] [blame] | 15 | import tempfile |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 16 | import unittest |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 17 | import urlparse |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 18 | |
| 19 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 20 | |
| 21 | from testing_support.auto_stub import TestCase |
| 22 | |
Edward Lemur | 5ba1e9c | 2018-07-23 18:19:02 +0000 | [diff] [blame] | 23 | import metrics |
| 24 | # We have to disable monitoring before importing git_cl. |
| 25 | metrics.DISABLE_METRICS_COLLECTION = True |
| 26 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 27 | import git_cl |
iannucci@chromium.org | 9e84927 | 2014-04-04 00:31:55 +0000 | [diff] [blame] | 28 | import git_common |
tandrii@chromium.org | 57d8654 | 2016-03-04 16:11:32 +0000 | [diff] [blame] | 29 | import git_footers |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 30 | import subprocess2 |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 31 | |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 32 | def callError(code=1, cmd='', cwd='', stdout='', stderr=''): |
| 33 | return subprocess2.CalledProcessError(code, cmd, cwd, stdout, stderr) |
| 34 | |
| 35 | |
| 36 | CERR1 = callError(1) |
| 37 | |
| 38 | |
Aaron Gable | 9a03ae0 | 2017-11-03 11:31:07 -0700 | [diff] [blame] | 39 | def MakeNamedTemporaryFileMock(expected_content): |
| 40 | class NamedTemporaryFileMock(object): |
| 41 | def __init__(self, *args, **kwargs): |
| 42 | self.name = '/tmp/named' |
| 43 | self.expected_content = expected_content |
| 44 | |
| 45 | def __enter__(self): |
| 46 | return self |
| 47 | |
| 48 | def __exit__(self, _type, _value, _tb): |
| 49 | pass |
| 50 | |
| 51 | def write(self, content): |
| 52 | if self.expected_content: |
| 53 | assert content == self.expected_content |
| 54 | |
| 55 | def close(self): |
| 56 | pass |
| 57 | |
| 58 | return NamedTemporaryFileMock |
| 59 | |
| 60 | |
martiniss@chromium.org | d6648e2 | 2016-04-29 19:22:16 +0000 | [diff] [blame] | 61 | class ChangelistMock(object): |
| 62 | # A class variable so we can access it when we don't have access to the |
| 63 | # instance that's being set. |
| 64 | desc = "" |
| 65 | def __init__(self, **kwargs): |
| 66 | pass |
| 67 | def GetIssue(self): |
| 68 | return 1 |
Kenneth Russell | 61e2ed4 | 2017-02-15 11:47:13 -0800 | [diff] [blame] | 69 | def GetDescription(self, force=False): |
martiniss@chromium.org | d6648e2 | 2016-04-29 19:22:16 +0000 | [diff] [blame] | 70 | return ChangelistMock.desc |
dsansome | e2d6fd9 | 2016-09-08 00:10:47 -0700 | [diff] [blame] | 71 | def UpdateDescription(self, desc, force=False): |
martiniss@chromium.org | d6648e2 | 2016-04-29 19:22:16 +0000 | [diff] [blame] | 72 | ChangelistMock.desc = desc |
| 73 | |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 74 | |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 75 | class PresubmitMock(object): |
| 76 | def __init__(self, *args, **kwargs): |
| 77 | self.reviewers = [] |
Daniel Cheng | 7227d21 | 2017-11-17 08:12:37 -0800 | [diff] [blame] | 78 | self.more_cc = ['chromium-reviews+test-more-cc@chromium.org'] |
| 79 | |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 80 | @staticmethod |
| 81 | def should_continue(): |
| 82 | return True |
| 83 | |
| 84 | |
| 85 | class RietveldMock(object): |
| 86 | def __init__(self, *args, **kwargs): |
| 87 | pass |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 88 | |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 89 | @staticmethod |
Kenneth Russell | 61e2ed4 | 2017-02-15 11:47:13 -0800 | [diff] [blame] | 90 | def get_description(issue, force=False): |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 91 | return 'Issue: %d' % issue |
| 92 | |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 93 | @staticmethod |
| 94 | def get_issue_properties(_issue, _messages): |
| 95 | return { |
| 96 | 'reviewers': ['joe@chromium.org', 'john@chromium.org'], |
| 97 | 'messages': [ |
| 98 | { |
| 99 | 'approval': True, |
Aaron Gable | a1bab27 | 2017-04-11 16:38:18 -0700 | [diff] [blame] | 100 | 'disapproval': False, |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 101 | 'sender': 'john@chromium.org', |
| 102 | }, |
| 103 | ], |
Andrii Shyshkalov | 06a2502 | 2016-11-24 16:47:00 +0100 | [diff] [blame] | 104 | 'patchsets': [1, 20001], |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 105 | } |
| 106 | |
iannucci | e53c935 | 2016-08-17 14:40:40 -0700 | [diff] [blame] | 107 | @staticmethod |
| 108 | def close_issue(_issue): |
| 109 | return 'Closed' |
| 110 | |
skobes | 6468b90 | 2016-10-24 08:45:10 -0700 | [diff] [blame] | 111 | @staticmethod |
| 112 | def get_patch(issue, patchset): |
| 113 | return 'patch set from issue %s patchset %s' % (issue, patchset) |
| 114 | |
Andrii Shyshkalov | 06a2502 | 2016-11-24 16:47:00 +0100 | [diff] [blame] | 115 | @staticmethod |
| 116 | def update_description(_issue, _description): |
| 117 | return 'Updated' |
| 118 | |
| 119 | @staticmethod |
| 120 | def add_comment(_issue, _comment): |
| 121 | return 'Commented' |
| 122 | |
| 123 | |
skobes | 6468b90 | 2016-10-24 08:45:10 -0700 | [diff] [blame] | 124 | class GitCheckoutMock(object): |
| 125 | def __init__(self, *args, **kwargs): |
| 126 | pass |
| 127 | |
| 128 | @staticmethod |
| 129 | def reset(): |
| 130 | GitCheckoutMock.conflict = False |
| 131 | |
| 132 | def apply_patch(self, p): |
| 133 | if GitCheckoutMock.conflict: |
| 134 | raise Exception('failed') |
| 135 | |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 136 | |
| 137 | class WatchlistsMock(object): |
| 138 | def __init__(self, _): |
| 139 | pass |
| 140 | @staticmethod |
| 141 | def GetWatchersForPaths(_): |
| 142 | return ['joe@example.com'] |
| 143 | |
| 144 | |
ukai@chromium.org | 78c4b98 | 2012-02-14 02:20:26 +0000 | [diff] [blame] | 145 | class CodereviewSettingsFileMock(object): |
| 146 | def __init__(self): |
| 147 | pass |
Quinten Yearsley | b2cc4a9 | 2016-12-15 13:53:26 -0800 | [diff] [blame] | 148 | # pylint: disable=no-self-use |
ukai@chromium.org | 78c4b98 | 2012-02-14 02:20:26 +0000 | [diff] [blame] | 149 | def read(self): |
| 150 | return ("CODE_REVIEW_SERVER: gerrit.chromium.org\n" + |
andybons@chromium.org | 11f46eb | 2016-02-02 19:26:51 +0000 | [diff] [blame] | 151 | "GERRIT_HOST: True\n") |
ukai@chromium.org | 78c4b98 | 2012-02-14 02:20:26 +0000 | [diff] [blame] | 152 | |
| 153 | |
vadimsh@chromium.org | eed4df3 | 2015-04-10 21:30:20 +0000 | [diff] [blame] | 154 | class AuthenticatorMock(object): |
| 155 | def __init__(self, *_args): |
| 156 | pass |
| 157 | def has_cached_credentials(self): |
| 158 | return True |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 159 | def authorize(self, http): |
| 160 | return http |
vadimsh@chromium.org | eed4df3 | 2015-04-10 21:30:20 +0000 | [diff] [blame] | 161 | |
| 162 | |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 163 | def CookiesAuthenticatorMockFactory(hosts_with_creds=None, same_auth=False): |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 164 | """Use to mock Gerrit/Git credentials from ~/.netrc or ~/.gitcookies. |
| 165 | |
| 166 | Usage: |
| 167 | >>> self.mock(git_cl.gerrit_util, "CookiesAuthenticator", |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 168 | CookiesAuthenticatorMockFactory({'host': ('user', _, 'pass')}) |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 169 | |
| 170 | OR |
| 171 | >>> self.mock(git_cl.gerrit_util, "CookiesAuthenticator", |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 172 | CookiesAuthenticatorMockFactory( |
| 173 | same_auth=('user', '', 'pass')) |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 174 | """ |
| 175 | class CookiesAuthenticatorMock(git_cl.gerrit_util.CookiesAuthenticator): |
Quinten Yearsley | b2cc4a9 | 2016-12-15 13:53:26 -0800 | [diff] [blame] | 176 | def __init__(self): # pylint: disable=super-init-not-called |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 177 | # Intentionally not calling super() because it reads actual cookie files. |
| 178 | pass |
| 179 | @classmethod |
| 180 | def get_gitcookies_path(cls): |
| 181 | return '~/.gitcookies' |
| 182 | @classmethod |
| 183 | def get_netrc_path(cls): |
| 184 | return '~/.netrc' |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 185 | def _get_auth_for_host(self, host): |
| 186 | if same_auth: |
| 187 | return same_auth |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 188 | return (hosts_with_creds or {}).get(host) |
| 189 | return CookiesAuthenticatorMock |
| 190 | |
Aaron Gable | 9a03ae0 | 2017-11-03 11:31:07 -0700 | [diff] [blame] | 191 | |
kmarshall | 9249e01 | 2016-08-23 12:02:16 -0700 | [diff] [blame] | 192 | class MockChangelistWithBranchAndIssue(): |
| 193 | def __init__(self, branch, issue): |
| 194 | self.branch = branch |
| 195 | self.issue = issue |
| 196 | def GetBranch(self): |
| 197 | return self.branch |
| 198 | def GetIssue(self): |
| 199 | return self.issue |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 200 | |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 201 | |
| 202 | class SystemExitMock(Exception): |
| 203 | pass |
| 204 | |
| 205 | |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 206 | class TestGitClBasic(unittest.TestCase): |
Andrii Shyshkalov | 3186301 | 2017-02-08 11:35:12 +0100 | [diff] [blame] | 207 | def test_get_description(self): |
| 208 | cl = git_cl.Changelist(issue=1, codereview='rietveld', |
| 209 | codereview_host='host') |
| 210 | cl.description = 'x' |
| 211 | cl.has_description = True |
Kenneth Russell | 61e2ed4 | 2017-02-15 11:47:13 -0800 | [diff] [blame] | 212 | cl._codereview_impl.FetchDescription = lambda *a, **kw: 'y' |
Andrii Shyshkalov | 3186301 | 2017-02-08 11:35:12 +0100 | [diff] [blame] | 213 | self.assertEquals(cl.GetDescription(), 'x') |
| 214 | self.assertEquals(cl.GetDescription(force=True), 'y') |
| 215 | self.assertEquals(cl.GetDescription(), 'y') |
| 216 | |
Robert Iannucci | 09f1f3d | 2017-03-28 16:54:32 -0700 | [diff] [blame] | 217 | def test_description_footers(self): |
| 218 | cl = git_cl.Changelist(issue=1, codereview='gerrit', |
| 219 | codereview_host='host') |
| 220 | cl.description = '\n'.join([ |
| 221 | 'This is some message', |
| 222 | '', |
| 223 | 'It has some lines', |
| 224 | 'and, also', |
| 225 | '', |
| 226 | 'Some: Really', |
| 227 | 'Awesome: Footers', |
| 228 | ]) |
| 229 | cl.has_description = True |
| 230 | cl._codereview_impl.UpdateDescriptionRemote = lambda *a, **kw: 'y' |
| 231 | msg, footers = cl.GetDescriptionFooters() |
| 232 | self.assertEquals( |
| 233 | msg, ['This is some message', '', 'It has some lines', 'and, also']) |
| 234 | self.assertEquals(footers, [('Some', 'Really'), ('Awesome', 'Footers')]) |
| 235 | |
| 236 | msg.append('wut') |
| 237 | footers.append(('gnarly-dude', 'beans')) |
| 238 | cl.UpdateDescriptionFooters(msg, footers) |
| 239 | self.assertEquals(cl.GetDescription().splitlines(), [ |
| 240 | 'This is some message', |
| 241 | '', |
| 242 | 'It has some lines', |
| 243 | 'and, also', |
| 244 | 'wut' |
| 245 | '', |
| 246 | 'Some: Really', |
| 247 | 'Awesome: Footers', |
| 248 | 'Gnarly-Dude: beans', |
| 249 | ]) |
| 250 | |
tandrii | f9aefb7 | 2016-07-01 09:06:51 -0700 | [diff] [blame] | 251 | def test_get_bug_line_values(self): |
| 252 | f = lambda p, bugs: list(git_cl._get_bug_line_values(p, bugs)) |
| 253 | self.assertEqual(f('', ''), []) |
| 254 | self.assertEqual(f('', '123,v8:456'), ['123', 'v8:456']) |
| 255 | self.assertEqual(f('v8', '456'), ['v8:456']) |
| 256 | self.assertEqual(f('v8', 'chromium:123,456'), ['v8:456', 'chromium:123']) |
| 257 | # Not nice, but not worth carying. |
| 258 | self.assertEqual(f('v8', 'chromium:123,456,v8:123'), |
| 259 | ['v8:456', 'chromium:123', 'v8:123']) |
| 260 | |
Andrii Shyshkalov | 15e50cc | 2016-12-02 14:34:08 +0100 | [diff] [blame] | 261 | def _test_git_number(self, parent_msg, dest_ref, child_msg, |
| 262 | parent_hash='parenthash'): |
| 263 | desc = git_cl.ChangeDescription(child_msg) |
| 264 | desc.update_with_git_number_footers(parent_hash, parent_msg, dest_ref) |
| 265 | return desc.description |
| 266 | |
| 267 | def assertEqualByLine(self, actual, expected): |
| 268 | self.assertEqual(actual.splitlines(), expected.splitlines()) |
| 269 | |
| 270 | def test_git_number_bad_parent(self): |
| 271 | with self.assertRaises(ValueError): |
| 272 | self._test_git_number('Parent', 'refs/heads/master', 'Child') |
| 273 | |
| 274 | def test_git_number_bad_parent_footer(self): |
| 275 | with self.assertRaises(AssertionError): |
| 276 | self._test_git_number( |
| 277 | 'Parent\n' |
| 278 | '\n' |
| 279 | 'Cr-Commit-Position: wrong', |
| 280 | 'refs/heads/master', 'Child') |
| 281 | |
| 282 | def test_git_number_bad_lineage_ignored(self): |
| 283 | actual = self._test_git_number( |
| 284 | 'Parent\n' |
| 285 | '\n' |
| 286 | 'Cr-Commit-Position: refs/heads/master@{#1}\n' |
| 287 | 'Cr-Branched-From: mustBeReal40CharHash-branch@{#pos}', |
| 288 | 'refs/heads/master', 'Child') |
| 289 | self.assertEqualByLine( |
| 290 | actual, |
| 291 | 'Child\n' |
| 292 | '\n' |
| 293 | 'Cr-Commit-Position: refs/heads/master@{#2}\n' |
| 294 | 'Cr-Branched-From: mustBeReal40CharHash-branch@{#pos}') |
| 295 | |
| 296 | def test_git_number_same_branch(self): |
| 297 | actual = self._test_git_number( |
| 298 | 'Parent\n' |
| 299 | '\n' |
| 300 | 'Cr-Commit-Position: refs/heads/master@{#12}', |
| 301 | dest_ref='refs/heads/master', |
| 302 | child_msg='Child') |
| 303 | self.assertEqualByLine( |
| 304 | actual, |
| 305 | 'Child\n' |
| 306 | '\n' |
| 307 | 'Cr-Commit-Position: refs/heads/master@{#13}') |
| 308 | |
Andrii Shyshkalov | de37c01 | 2017-07-06 21:06:50 +0200 | [diff] [blame] | 309 | def test_git_number_same_branch_mixed_footers(self): |
| 310 | actual = self._test_git_number( |
| 311 | 'Parent\n' |
| 312 | '\n' |
| 313 | 'Cr-Commit-Position: refs/heads/master@{#12}', |
| 314 | dest_ref='refs/heads/master', |
| 315 | child_msg='Child\n' |
| 316 | '\n' |
| 317 | 'Broken-by: design\n' |
| 318 | 'BUG=123') |
| 319 | self.assertEqualByLine( |
| 320 | actual, |
| 321 | 'Child\n' |
| 322 | '\n' |
| 323 | 'Broken-by: design\n' |
| 324 | 'BUG=123\n' |
| 325 | 'Cr-Commit-Position: refs/heads/master@{#13}') |
| 326 | |
Andrii Shyshkalov | 15e50cc | 2016-12-02 14:34:08 +0100 | [diff] [blame] | 327 | def test_git_number_same_branch_with_originals(self): |
| 328 | actual = self._test_git_number( |
| 329 | 'Parent\n' |
| 330 | '\n' |
| 331 | 'Cr-Commit-Position: refs/heads/master@{#12}', |
| 332 | dest_ref='refs/heads/master', |
| 333 | child_msg='Child\n' |
| 334 | '\n' |
| 335 | 'Some users are smart and insert their own footers\n' |
| 336 | '\n' |
| 337 | 'Cr-Whatever: value\n' |
| 338 | 'Cr-Commit-Position: refs/copy/paste@{#22}') |
| 339 | self.assertEqualByLine( |
| 340 | actual, |
| 341 | 'Child\n' |
| 342 | '\n' |
| 343 | 'Some users are smart and insert their own footers\n' |
| 344 | '\n' |
| 345 | 'Cr-Original-Whatever: value\n' |
| 346 | 'Cr-Original-Commit-Position: refs/copy/paste@{#22}\n' |
| 347 | 'Cr-Commit-Position: refs/heads/master@{#13}') |
| 348 | |
| 349 | def test_git_number_new_branch(self): |
| 350 | actual = self._test_git_number( |
| 351 | 'Parent\n' |
| 352 | '\n' |
| 353 | 'Cr-Commit-Position: refs/heads/master@{#12}', |
| 354 | dest_ref='refs/heads/branch', |
| 355 | child_msg='Child') |
| 356 | self.assertEqualByLine( |
| 357 | actual, |
| 358 | 'Child\n' |
| 359 | '\n' |
| 360 | 'Cr-Commit-Position: refs/heads/branch@{#1}\n' |
| 361 | 'Cr-Branched-From: parenthash-refs/heads/master@{#12}') |
| 362 | |
| 363 | def test_git_number_lineage(self): |
| 364 | actual = self._test_git_number( |
| 365 | 'Parent\n' |
| 366 | '\n' |
| 367 | 'Cr-Commit-Position: refs/heads/branch@{#1}\n' |
| 368 | 'Cr-Branched-From: somehash-refs/heads/master@{#12}', |
| 369 | dest_ref='refs/heads/branch', |
| 370 | child_msg='Child') |
| 371 | self.assertEqualByLine( |
| 372 | actual, |
| 373 | 'Child\n' |
| 374 | '\n' |
| 375 | 'Cr-Commit-Position: refs/heads/branch@{#2}\n' |
| 376 | 'Cr-Branched-From: somehash-refs/heads/master@{#12}') |
| 377 | |
| 378 | def test_git_number_moooooooore_lineage(self): |
| 379 | actual = self._test_git_number( |
| 380 | 'Parent\n' |
| 381 | '\n' |
| 382 | 'Cr-Commit-Position: refs/heads/branch@{#5}\n' |
| 383 | 'Cr-Branched-From: somehash-refs/heads/master@{#12}', |
| 384 | dest_ref='refs/heads/mooore', |
| 385 | child_msg='Child') |
| 386 | self.assertEqualByLine( |
| 387 | actual, |
| 388 | 'Child\n' |
| 389 | '\n' |
| 390 | 'Cr-Commit-Position: refs/heads/mooore@{#1}\n' |
| 391 | 'Cr-Branched-From: parenthash-refs/heads/branch@{#5}\n' |
| 392 | 'Cr-Branched-From: somehash-refs/heads/master@{#12}') |
| 393 | |
Andrii Shyshkalov | b5effa1 | 2016-12-14 19:35:12 +0100 | [diff] [blame] | 394 | def test_git_number_ever_moooooooore_lineage(self): |
Robert Iannucci | 456b0d6 | 2018-03-13 19:15:50 -0700 | [diff] [blame] | 395 | self.maxDiff = 10000 # pylint: disable=attribute-defined-outside-init |
Andrii Shyshkalov | b5effa1 | 2016-12-14 19:35:12 +0100 | [diff] [blame] | 396 | actual = self._test_git_number( |
| 397 | 'CQ commit on fresh new branch + numbering.\n' |
| 398 | '\n' |
| 399 | 'NOTRY=True\n' |
| 400 | 'NOPRESUBMIT=True\n' |
| 401 | 'BUG=\n' |
| 402 | '\n' |
| 403 | 'Review-Url: https://codereview.chromium.org/2577703003\n' |
| 404 | 'Cr-Commit-Position: refs/heads/gnumb-test/br@{#1}\n' |
| 405 | 'Cr-Branched-From: 0749ff9edc-refs/heads/gnumb-test/cq@{#4}\n' |
| 406 | 'Cr-Branched-From: 5c49df2da6-refs/heads/master@{#41618}', |
| 407 | dest_ref='refs/heads/gnumb-test/cl', |
| 408 | child_msg='git cl on fresh new branch + numbering.\n' |
| 409 | '\n' |
| 410 | 'Review-Url: https://codereview.chromium.org/2575043003 .\n') |
| 411 | self.assertEqualByLine( |
| 412 | actual, |
| 413 | 'git cl on fresh new branch + numbering.\n' |
| 414 | '\n' |
| 415 | 'Review-Url: https://codereview.chromium.org/2575043003 .\n' |
| 416 | 'Cr-Commit-Position: refs/heads/gnumb-test/cl@{#1}\n' |
| 417 | 'Cr-Branched-From: parenthash-refs/heads/gnumb-test/br@{#1}\n' |
| 418 | 'Cr-Branched-From: 0749ff9edc-refs/heads/gnumb-test/cq@{#4}\n' |
| 419 | 'Cr-Branched-From: 5c49df2da6-refs/heads/master@{#41618}') |
Andrii Shyshkalov | 15e50cc | 2016-12-02 14:34:08 +0100 | [diff] [blame] | 420 | |
| 421 | def test_git_number_cherry_pick(self): |
| 422 | actual = self._test_git_number( |
| 423 | 'Parent\n' |
| 424 | '\n' |
| 425 | 'Cr-Commit-Position: refs/heads/branch@{#1}\n' |
| 426 | 'Cr-Branched-From: somehash-refs/heads/master@{#12}', |
| 427 | dest_ref='refs/heads/branch', |
| 428 | child_msg='Child, which is cherry-pick from master\n' |
| 429 | '\n' |
| 430 | 'Cr-Commit-Position: refs/heads/master@{#100}\n' |
| 431 | '(cherry picked from commit deadbeef12345678deadbeef12345678deadbeef)') |
| 432 | self.assertEqualByLine( |
| 433 | actual, |
| 434 | 'Child, which is cherry-pick from master\n' |
| 435 | '\n' |
| 436 | '(cherry picked from commit deadbeef12345678deadbeef12345678deadbeef)\n' |
| 437 | '\n' |
| 438 | 'Cr-Original-Commit-Position: refs/heads/master@{#100}\n' |
| 439 | 'Cr-Commit-Position: refs/heads/branch@{#2}\n' |
| 440 | 'Cr-Branched-From: somehash-refs/heads/master@{#12}') |
| 441 | |
Andrii Shyshkalov | d4c8673 | 2018-09-25 04:29:31 +0000 | [diff] [blame] | 442 | def test_gerrit_mirror_hack(self): |
| 443 | cr = 'chromium-review.googlesource.com' |
| 444 | url0 = 'https://%s/a/changes/x?a=b' % cr |
| 445 | origMirrors = git_cl.gerrit_util._GERRIT_MIRROR_PREFIXES |
| 446 | try: |
| 447 | git_cl.gerrit_util._GERRIT_MIRROR_PREFIXES = ['us1', 'us2'] |
| 448 | url1 = git_cl.gerrit_util._UseGerritMirror(url0, cr) |
| 449 | url2 = git_cl.gerrit_util._UseGerritMirror(url1, cr) |
| 450 | url3 = git_cl.gerrit_util._UseGerritMirror(url2, cr) |
| 451 | |
| 452 | self.assertNotEqual(url1, url2) |
| 453 | self.assertEqual(sorted((url1, url2)), [ |
| 454 | 'https://us1-mirror-chromium-review.googlesource.com/a/changes/x?a=b', |
| 455 | 'https://us2-mirror-chromium-review.googlesource.com/a/changes/x?a=b']) |
| 456 | self.assertEqual(url1, url3) |
| 457 | finally: |
| 458 | git_cl.gerrit_util._GERRIT_MIRROR_PREFIXES = origMirrors |
| 459 | |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 460 | |
Andrii Shyshkalov | 90f3192 | 2017-04-10 16:10:21 +0200 | [diff] [blame] | 461 | class TestParseIssueURL(unittest.TestCase): |
| 462 | def _validate(self, parsed, issue=None, patchset=None, hostname=None, |
| 463 | codereview=None, fail=False): |
| 464 | self.assertIsNotNone(parsed) |
| 465 | if fail: |
| 466 | self.assertFalse(parsed.valid) |
| 467 | return |
| 468 | self.assertTrue(parsed.valid) |
| 469 | self.assertEqual(parsed.issue, issue) |
| 470 | self.assertEqual(parsed.patchset, patchset) |
| 471 | self.assertEqual(parsed.hostname, hostname) |
| 472 | self.assertEqual(parsed.codereview, codereview) |
| 473 | |
| 474 | def _run_and_validate(self, func, url, *args, **kwargs): |
| 475 | result = func(urlparse.urlparse(url)) |
| 476 | if kwargs.pop('fail', False): |
| 477 | self.assertIsNone(result) |
| 478 | return None |
| 479 | self._validate(result, *args, fail=False, **kwargs) |
| 480 | |
| 481 | def test_rietveld(self): |
| 482 | def test(url, *args, **kwargs): |
| 483 | self._run_and_validate(git_cl._RietveldChangelistImpl.ParseIssueURL, url, |
| 484 | *args, codereview='rietveld', **kwargs) |
| 485 | |
| 486 | test('http://codereview.chromium.org/123', |
| 487 | 123, None, 'codereview.chromium.org') |
| 488 | test('https://codereview.chromium.org/123', |
| 489 | 123, None, 'codereview.chromium.org') |
| 490 | test('https://codereview.chromium.org/123/', |
| 491 | 123, None, 'codereview.chromium.org') |
| 492 | test('https://codereview.chromium.org/123/whatever', |
| 493 | 123, None, 'codereview.chromium.org') |
| 494 | test('https://codereview.chromium.org/123/#ps20001', |
| 495 | 123, 20001, 'codereview.chromium.org') |
| 496 | test('http://codereview.chromium.org/download/issue123_4.diff', |
| 497 | 123, 4, 'codereview.chromium.org') |
| 498 | # This looks like bad Gerrit, but is actually valid Rietveld, too. |
| 499 | test('https://chrome-review.source.com/123/4/', |
| 500 | 123, None, 'chrome-review.source.com') |
| 501 | |
| 502 | test('https://codereview.chromium.org/deadbeaf', fail=True) |
| 503 | test('https://codereview.chromium.org/api/123', fail=True) |
| 504 | test('bad://codereview.chromium.org/123', fail=True) |
| 505 | test('http://codereview.chromium.org/download/issue123_4.diffff', fail=True) |
| 506 | |
| 507 | def test_gerrit(self): |
| 508 | def test(url, issue=None, patchset=None, hostname=None, fail=None): |
| 509 | self._test_ParseIssueUrl( |
| 510 | git_cl._GerritChangelistImpl.ParseIssueURL, |
| 511 | url, issue, patchset, hostname, fail) |
| 512 | def test(url, *args, **kwargs): |
| 513 | self._run_and_validate(git_cl._GerritChangelistImpl.ParseIssueURL, url, |
| 514 | *args, codereview='gerrit', **kwargs) |
| 515 | |
| 516 | test('http://chrome-review.source.com/c/123', |
| 517 | 123, None, 'chrome-review.source.com') |
| 518 | test('https://chrome-review.source.com/c/123/', |
| 519 | 123, None, 'chrome-review.source.com') |
| 520 | test('https://chrome-review.source.com/c/123/4', |
| 521 | 123, 4, 'chrome-review.source.com') |
| 522 | test('https://chrome-review.source.com/#/c/123/4', |
| 523 | 123, 4, 'chrome-review.source.com') |
| 524 | test('https://chrome-review.source.com/c/123/4', |
| 525 | 123, 4, 'chrome-review.source.com') |
| 526 | test('https://chrome-review.source.com/123', |
| 527 | 123, None, 'chrome-review.source.com') |
| 528 | test('https://chrome-review.source.com/123/4', |
| 529 | 123, 4, 'chrome-review.source.com') |
| 530 | |
| 531 | test('https://chrome-review.source.com/c/123/1/whatisthis', fail=True) |
| 532 | test('https://chrome-review.source.com/c/abc/', fail=True) |
| 533 | test('ssh://chrome-review.source.com/c/123/1/', fail=True) |
| 534 | |
| 535 | def test_ParseIssueNumberArgument(self): |
| 536 | def test(arg, *args, **kwargs): |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 537 | codereview_hint = kwargs.pop('hint', None) |
| 538 | self._validate(git_cl.ParseIssueNumberArgument(arg, codereview_hint), |
| 539 | *args, **kwargs) |
Andrii Shyshkalov | 90f3192 | 2017-04-10 16:10:21 +0200 | [diff] [blame] | 540 | |
| 541 | test('123', 123) |
| 542 | test('', fail=True) |
| 543 | test('abc', fail=True) |
| 544 | test('123/1', fail=True) |
| 545 | test('123a', fail=True) |
| 546 | test('ssh://chrome-review.source.com/#/c/123/4/', fail=True) |
| 547 | # Rietveld. |
| 548 | test('https://codereview.source.com/www123', fail=True) |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 549 | # Matches both, but we take Rietveld now by default. |
Andrii Shyshkalov | 90f3192 | 2017-04-10 16:10:21 +0200 | [diff] [blame] | 550 | test('https://codereview.source.com/123', |
| 551 | 123, None, 'codereview.source.com', 'rietveld') |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 552 | # Matches both, but we take Gerrit if specifically requested. |
| 553 | test('https://codereview.source.com/123', |
| 554 | 123, None, 'codereview.source.com', 'gerrit', |
| 555 | hint='gerrit') |
Andrii Shyshkalov | 90f3192 | 2017-04-10 16:10:21 +0200 | [diff] [blame] | 556 | # Gerrrit. |
| 557 | test('https://chrome-review.source.com/c/123/4', |
| 558 | 123, 4, 'chrome-review.source.com', 'gerrit') |
| 559 | test('https://chrome-review.source.com/bad/123/4', fail=True) |
| 560 | |
| 561 | |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 562 | class GitCookiesCheckerTest(TestCase): |
Andrii Shyshkalov | 9780050 | 2017-03-16 16:04:32 +0100 | [diff] [blame] | 563 | def setUp(self): |
| 564 | super(GitCookiesCheckerTest, self).setUp() |
| 565 | self.c = git_cl._GitCookiesChecker() |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 566 | self.c._all_hosts = [] |
Andrii Shyshkalov | 9780050 | 2017-03-16 16:04:32 +0100 | [diff] [blame] | 567 | |
| 568 | def mock_hosts_creds(self, subhost_identity_pairs): |
| 569 | def ensure_googlesource(h): |
| 570 | if not h.endswith(self.c._GOOGLESOURCE): |
| 571 | assert not h.endswith('.') |
| 572 | return h + '.' + self.c._GOOGLESOURCE |
| 573 | return h |
| 574 | self.c._all_hosts = [(ensure_googlesource(h), i, '.gitcookies') |
| 575 | for h, i in subhost_identity_pairs] |
| 576 | |
Andrii Shyshkalov | 0d2dea0 | 2017-07-17 15:17:55 +0200 | [diff] [blame] | 577 | def test_identity_parsing(self): |
| 578 | self.assertEqual(self.c._parse_identity('ldap.google.com'), |
| 579 | ('ldap', 'google.com')) |
| 580 | self.assertEqual(self.c._parse_identity('git-ldap.example.com'), |
| 581 | ('ldap', 'example.com')) |
| 582 | # Specical case because we know there are no subdomains in chromium.org. |
| 583 | self.assertEqual(self.c._parse_identity('git-note.period.chromium.org'), |
| 584 | ('note.period', 'chromium.org')) |
Lei Zhang | d3f769a | 2017-12-15 15:16:14 -0800 | [diff] [blame] | 585 | # Pathological: ".period." can be either username OR domain, more likely |
| 586 | # domain. |
Andrii Shyshkalov | 0d2dea0 | 2017-07-17 15:17:55 +0200 | [diff] [blame] | 587 | self.assertEqual(self.c._parse_identity('git-note.period.example.com'), |
| 588 | ('note', 'period.example.com')) |
| 589 | |
Andrii Shyshkalov | 9780050 | 2017-03-16 16:04:32 +0100 | [diff] [blame] | 590 | def test_analysis_nothing(self): |
| 591 | self.c._all_hosts = [] |
| 592 | self.assertFalse(self.c.has_generic_host()) |
| 593 | self.assertEqual(set(), self.c.get_conflicting_hosts()) |
| 594 | self.assertEqual(set(), self.c.get_duplicated_hosts()) |
| 595 | self.assertEqual(set(), self.c.get_partially_configured_hosts()) |
| 596 | self.assertEqual(set(), self.c.get_hosts_with_wrong_identities()) |
| 597 | |
| 598 | def test_analysis(self): |
| 599 | self.mock_hosts_creds([ |
| 600 | ('.googlesource.com', 'git-example.chromium.org'), |
| 601 | |
| 602 | ('chromium', 'git-example.google.com'), |
| 603 | ('chromium-review', 'git-example.google.com'), |
| 604 | ('chrome-internal', 'git-example.chromium.org'), |
| 605 | ('chrome-internal-review', 'git-example.chromium.org'), |
| 606 | ('conflict', 'git-example.google.com'), |
| 607 | ('conflict-review', 'git-example.chromium.org'), |
| 608 | ('dup', 'git-example.google.com'), |
| 609 | ('dup', 'git-example.google.com'), |
| 610 | ('dup-review', 'git-example.google.com'), |
| 611 | ('partial', 'git-example.google.com'), |
Andrii Shyshkalov | c817382 | 2017-07-10 12:10:53 +0200 | [diff] [blame] | 612 | ('gpartial-review', 'git-example.google.com'), |
Andrii Shyshkalov | 9780050 | 2017-03-16 16:04:32 +0100 | [diff] [blame] | 613 | ]) |
| 614 | self.assertTrue(self.c.has_generic_host()) |
| 615 | self.assertEqual(set(['conflict.googlesource.com']), |
| 616 | self.c.get_conflicting_hosts()) |
| 617 | self.assertEqual(set(['dup.googlesource.com']), |
| 618 | self.c.get_duplicated_hosts()) |
Andrii Shyshkalov | c817382 | 2017-07-10 12:10:53 +0200 | [diff] [blame] | 619 | self.assertEqual(set(['partial.googlesource.com', |
| 620 | 'gpartial-review.googlesource.com']), |
Andrii Shyshkalov | 9780050 | 2017-03-16 16:04:32 +0100 | [diff] [blame] | 621 | self.c.get_partially_configured_hosts()) |
| 622 | self.assertEqual(set(['chromium.googlesource.com', |
| 623 | 'chrome-internal.googlesource.com']), |
| 624 | self.c.get_hosts_with_wrong_identities()) |
| 625 | |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 626 | def test_report_no_problems(self): |
| 627 | self.test_analysis_nothing() |
| 628 | self.mock(sys, 'stdout', StringIO.StringIO()) |
| 629 | self.assertFalse(self.c.find_and_report_problems()) |
| 630 | self.assertEqual(sys.stdout.getvalue(), '') |
| 631 | |
| 632 | def test_report(self): |
| 633 | self.test_analysis() |
| 634 | self.mock(sys, 'stdout', StringIO.StringIO()) |
Andrii Shyshkalov | c817382 | 2017-07-10 12:10:53 +0200 | [diff] [blame] | 635 | self.mock(git_cl.gerrit_util.CookiesAuthenticator, 'get_gitcookies_path', |
| 636 | classmethod(lambda _: '~/.gitcookies')) |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 637 | self.assertTrue(self.c.find_and_report_problems()) |
| 638 | with open(os.path.join(os.path.dirname(__file__), |
| 639 | 'git_cl_creds_check_report.txt')) as f: |
| 640 | expected = f.read() |
| 641 | def by_line(text): |
| 642 | return [l.rstrip() for l in text.rstrip().splitlines()] |
Robert Iannucci | 456b0d6 | 2018-03-13 19:15:50 -0700 | [diff] [blame] | 643 | self.maxDiff = 10000 # pylint: disable=attribute-defined-outside-init |
Andrii Shyshkalov | 4812e61 | 2017-03-27 17:22:57 +0200 | [diff] [blame] | 644 | self.assertEqual(by_line(sys.stdout.getvalue().strip()), by_line(expected)) |
Andrii Shyshkalov | 9780050 | 2017-03-16 16:04:32 +0100 | [diff] [blame] | 645 | |
Nodir Turakulov | d0e2cd2 | 2017-11-15 10:22:06 -0800 | [diff] [blame] | 646 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 647 | class TestGitCl(TestCase): |
| 648 | def setUp(self): |
| 649 | super(TestGitCl, self).setUp() |
| 650 | self.calls = [] |
tandrii | 9d20675 | 2016-06-20 11:32:47 -0700 | [diff] [blame] | 651 | self._calls_done = [] |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 652 | self.mock(subprocess2, 'call', self._mocked_call) |
| 653 | self.mock(subprocess2, 'check_call', self._mocked_call) |
| 654 | self.mock(subprocess2, 'check_output', self._mocked_call) |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 655 | self.mock(subprocess2, 'communicate', |
| 656 | lambda *a, **kw: ([self._mocked_call(*a, **kw), ''], 0)) |
tandrii@chromium.org | a342c92 | 2016-03-16 07:08:25 +0000 | [diff] [blame] | 657 | self.mock(git_cl.gclient_utils, 'CheckCallAndFilter', self._mocked_call) |
sbc@chromium.org | 71437c0 | 2015-04-09 19:29:40 +0000 | [diff] [blame] | 658 | self.mock(git_common, 'is_dirty_git_tree', lambda x: False) |
iannucci@chromium.org | 9e84927 | 2014-04-04 00:31:55 +0000 | [diff] [blame] | 659 | self.mock(git_common, 'get_or_create_merge_base', |
| 660 | lambda *a: ( |
| 661 | self._mocked_call(['get_or_create_merge_base']+list(a)))) |
pgervais@chromium.org | 8ba38ff | 2015-06-11 21:41:25 +0000 | [diff] [blame] | 662 | self.mock(git_cl, 'BranchExists', lambda _: True) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 663 | self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '') |
Andrii Shyshkalov | d9fdc1f | 2018-09-27 02:13:09 +0000 | [diff] [blame^] | 664 | self.mock(git_cl, 'SaveDescriptionBackup', lambda _: |
| 665 | self._mocked_call('SaveDescriptionBackup')) |
Andrii Shyshkalov | abc26ac | 2017-03-14 14:49:38 +0100 | [diff] [blame] | 666 | self.mock(git_cl, 'ask_for_data', lambda *a, **k: self._mocked_call( |
Andrii Shyshkalov | d9fdc1f | 2018-09-27 02:13:09 +0000 | [diff] [blame^] | 667 | *(['ask_for_data'] + list(a)), **k)) |
phajdan.jr | e328cf9 | 2016-08-22 04:12:17 -0700 | [diff] [blame] | 668 | self.mock(git_cl, 'write_json', lambda path, contents: |
Andrii Shyshkalov | d9fdc1f | 2018-09-27 02:13:09 +0000 | [diff] [blame^] | 669 | self._mocked_call('write_json', path, contents)) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 670 | self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 671 | self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) |
maruel@chromium.org | 4bac4b5 | 2012-11-27 20:33:52 +0000 | [diff] [blame] | 672 | self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) |
skobes | 6468b90 | 2016-10-24 08:45:10 -0700 | [diff] [blame] | 673 | self.mock(git_cl.checkout, 'GitCheckout', GitCheckoutMock) |
| 674 | GitCheckoutMock.reset() |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 675 | self.mock(git_cl.upload, 'RealMain', self.fail) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 676 | self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock) |
vadimsh@chromium.org | eed4df3 | 2015-04-10 21:30:20 +0000 | [diff] [blame] | 677 | self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock) |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 678 | self.mock(git_cl.gerrit_util, 'GetChangeDetail', |
| 679 | lambda *args, **kwargs: self._mocked_call( |
| 680 | 'GetChangeDetail', *args, **kwargs)) |
Aaron Gable | 0ffdf2d | 2017-06-05 13:01:17 -0700 | [diff] [blame] | 681 | self.mock(git_cl.gerrit_util, 'GetChangeComments', |
| 682 | lambda *args, **kwargs: self._mocked_call( |
| 683 | 'GetChangeComments', *args, **kwargs)) |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 684 | self.mock(git_cl.gerrit_util, 'AddReviewers', |
Aaron Gable | 6dadfbf | 2017-05-09 14:27:58 -0700 | [diff] [blame] | 685 | lambda h, i, reviewers, ccs, notify: self._mocked_call( |
| 686 | 'AddReviewers', h, i, reviewers, ccs, notify)) |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 687 | self.mock(git_cl.gerrit_util, 'SetReview', |
Aaron Gable | fc62f76 | 2017-07-17 11:12:07 -0700 | [diff] [blame] | 688 | lambda h, i, msg=None, labels=None, notify=None: |
| 689 | self._mocked_call('SetReview', h, i, msg, labels, notify)) |
Andrii Shyshkalov | 733d4ec | 2018-04-19 11:48:58 -0700 | [diff] [blame] | 690 | self.mock(git_cl.gerrit_util.LuciContextAuthenticator, 'is_luci', |
| 691 | staticmethod(lambda: False)) |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 692 | self.mock(git_cl.gerrit_util.GceAuthenticator, 'is_gce', |
| 693 | classmethod(lambda _: False)) |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 694 | self.mock(git_cl, 'DieWithError', |
Christopher Lam | f732cd5 | 2017-01-24 12:40:11 +1100 | [diff] [blame] | 695 | lambda msg, change=None: self._mocked_call(['DieWithError', msg])) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 696 | # It's important to reset settings to not have inter-tests interference. |
| 697 | git_cl.settings = None |
| 698 | |
| 699 | def tearDown(self): |
wychen@chromium.org | 445c896 | 2015-04-28 23:30:05 +0000 | [diff] [blame] | 700 | try: |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 701 | self.assertEquals([], self.calls) |
| 702 | except AssertionError: |
wychen@chromium.org | 445c896 | 2015-04-28 23:30:05 +0000 | [diff] [blame] | 703 | if not self.has_failed(): |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 704 | raise |
| 705 | # Sadly, has_failed() returns True if this OR any other tests before this |
| 706 | # one have failed. |
Andrii Shyshkalov | e05d488 | 2017-04-12 14:34:49 +0200 | [diff] [blame] | 707 | git_cl.logging.error( |
| 708 | '!!!!!! IF YOU SEE THIS, READ BELOW, IT WILL SAVE YOUR TIME !!!!!\n' |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 709 | 'There are un-consumed self.calls after this test has finished.\n' |
| 710 | 'If you don\'t know which test this is, run:\n' |
Aaron Gable | 3a16ed1 | 2017-03-23 10:51:55 -0700 | [diff] [blame] | 711 | ' tests/git_cl_tests.py -v\n' |
Andrii Shyshkalov | e05d488 | 2017-04-12 14:34:49 +0200 | [diff] [blame] | 712 | 'If you are already running only this test, then **first** fix the ' |
| 713 | 'problem whose exception is emitted below by unittest runner.\n' |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 714 | 'Else, to be sure what\'s going on, run this test **alone** with \n' |
Aaron Gable | 3a16ed1 | 2017-03-23 10:51:55 -0700 | [diff] [blame] | 715 | ' tests/git_cl_tests.py TestGitCl.<name>\n' |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 716 | 'and follow instructions above.\n' + |
| 717 | '=' * 80) |
wychen@chromium.org | 445c896 | 2015-04-28 23:30:05 +0000 | [diff] [blame] | 718 | finally: |
| 719 | super(TestGitCl, self).tearDown() |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 720 | |
iannucci@chromium.org | 9e84927 | 2014-04-04 00:31:55 +0000 | [diff] [blame] | 721 | def _mocked_call(self, *args, **_kwargs): |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 722 | self.assertTrue( |
| 723 | self.calls, |
tandrii | 9d20675 | 2016-06-20 11:32:47 -0700 | [diff] [blame] | 724 | '@%d Expected: <Missing> Actual: %r' % (len(self._calls_done), args)) |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 725 | top = self.calls.pop(0) |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 726 | expected_args, result = top |
| 727 | |
maruel@chromium.org | e52678e | 2013-04-26 18:34:44 +0000 | [diff] [blame] | 728 | # Also logs otherwise it could get caught in a try/finally and be hard to |
| 729 | # diagnose. |
| 730 | if expected_args != args: |
tandrii | 9d20675 | 2016-06-20 11:32:47 -0700 | [diff] [blame] | 731 | N = 5 |
| 732 | prior_calls = '\n '.join( |
| 733 | '@%d: %r' % (len(self._calls_done) - N + i, c[0]) |
| 734 | for i, c in enumerate(self._calls_done[-N:])) |
| 735 | following_calls = '\n '.join( |
| 736 | '@%d: %r' % (len(self._calls_done) + i + 1, c[0]) |
| 737 | for i, c in enumerate(self.calls[:N])) |
| 738 | extended_msg = ( |
| 739 | 'A few prior calls:\n %s\n\n' |
| 740 | 'This (expected):\n @%d: %r\n' |
| 741 | 'This (actual):\n @%d: %r\n\n' |
| 742 | 'A few following expected calls:\n %s' % |
| 743 | (prior_calls, len(self._calls_done), expected_args, |
| 744 | len(self._calls_done), args, following_calls)) |
| 745 | git_cl.logging.error(extended_msg) |
| 746 | |
tandrii | 99a72f2 | 2016-08-17 14:33:24 -0700 | [diff] [blame] | 747 | self.fail('@%d\n' |
| 748 | ' Expected: %r\n' |
| 749 | ' Actual: %r' % ( |
tandrii | 9d20675 | 2016-06-20 11:32:47 -0700 | [diff] [blame] | 750 | len(self._calls_done), expected_args, args)) |
| 751 | |
| 752 | self._calls_done.append(top) |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 753 | if isinstance(result, Exception): |
| 754 | raise result |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 755 | return result |
| 756 | |
Andrii Shyshkalov | abc26ac | 2017-03-14 14:49:38 +0100 | [diff] [blame] | 757 | def test_ask_for_explicit_yes_true(self): |
| 758 | self.calls = [ |
| 759 | (('ask_for_data', 'prompt [Yes/No]: '), 'blah'), |
| 760 | (('ask_for_data', 'Please, type yes or no: '), 'ye'), |
| 761 | ] |
| 762 | self.assertTrue(git_cl.ask_for_explicit_yes('prompt')) |
| 763 | |
tandrii | 48df581 | 2016-10-17 03:55:37 -0700 | [diff] [blame] | 764 | def test_LoadCodereviewSettingsFromFile_gerrit(self): |
| 765 | codereview_file = StringIO.StringIO('GERRIT_HOST: true') |
| 766 | self.calls = [ |
| 767 | ((['git', 'config', '--unset-all', 'rietveld.cc'],), CERR1), |
| 768 | ((['git', 'config', '--unset-all', 'rietveld.private'],), CERR1), |
| 769 | ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), CERR1), |
| 770 | ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), CERR1), |
| 771 | ((['git', 'config', '--unset-all', 'rietveld.bug-prefix'],), CERR1), |
| 772 | ((['git', 'config', '--unset-all', 'rietveld.cpplint-regex'],), CERR1), |
tandrii | 48df581 | 2016-10-17 03:55:37 -0700 | [diff] [blame] | 773 | ((['git', 'config', '--unset-all', 'rietveld.cpplint-ignore-regex'],), |
| 774 | CERR1), |
| 775 | ((['git', 'config', '--unset-all', 'rietveld.project'],), CERR1), |
tandrii | 48df581 | 2016-10-17 03:55:37 -0700 | [diff] [blame] | 776 | ((['git', 'config', '--unset-all', 'rietveld.run-post-upload-hook'],), |
| 777 | CERR1), |
| 778 | ((['git', 'config', 'gerrit.host', 'true'],), ''), |
| 779 | ] |
| 780 | self.assertIsNone(git_cl.LoadCodereviewSettingsFromFile(codereview_file)) |
| 781 | |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 782 | @classmethod |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 783 | def _is_gerrit_calls(cls, gerrit=False): |
| 784 | return [((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 785 | ((['git', 'config', 'gerrit.host'],), 'True' if gerrit else '')] |
| 786 | |
| 787 | @classmethod |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 788 | def _upload_calls(cls, private, no_autocc): |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 789 | return (cls._rietveld_git_base_calls() + |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 790 | cls._git_upload_calls(private, no_autocc)) |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 791 | |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 792 | @classmethod |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 793 | def _rietveld_upload_no_rev_calls(cls): |
| 794 | return (cls._rietveld_git_base_calls() + [ |
Andrii Shyshkalov | 73827d1 | 2017-04-12 15:05:11 +0200 | [diff] [blame] | 795 | ((['git', 'config', 'core.editor'],), ''), |
| 796 | ]) |
jbroman@chromium.org | 615a262 | 2013-05-03 13:20:14 +0000 | [diff] [blame] | 797 | |
| 798 | @classmethod |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 799 | def _rietveld_git_base_calls(cls): |
| 800 | stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
| 801 | '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), '+dat') |
iannucci@chromium.org | 7954005 | 2012-10-19 23:15:26 +0000 | [diff] [blame] | 802 | |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 803 | return cls._is_gerrit_calls() + [ |
tandrii@chromium.org | 87985d2 | 2016-03-24 17:33:33 +0000 | [diff] [blame] | 804 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 805 | ((['git', 'config', 'branch.master.rietveldissue'],), CERR1), |
| 806 | ((['git', 'config', 'branch.master.gerritissue'],), CERR1), |
tandrii@chromium.org | aa5ced1 | 2016-03-29 09:41:14 +0000 | [diff] [blame] | 807 | ((['git', 'config', 'rietveld.server'],), |
| 808 | 'codereview.example.com'), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 809 | ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 810 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
iannucci@chromium.org | 9e84927 | 2014-04-04 00:31:55 +0000 | [diff] [blame] | 811 | ((['get_or_create_merge_base', 'master', 'master'],), |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 812 | 'fake_ancestor_sha'), |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 813 | ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 814 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 815 | ((['git', 'rev-parse', 'HEAD'],), '12345'), |
Aaron Gable | 7817f02 | 2017-12-12 09:43:17 -0800 | [diff] [blame] | 816 | ((['git', '-c', 'core.quotePath=false', 'diff', |
| 817 | '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', '.'],), |
maruel@chromium.org | 2e72bb1 | 2012-01-17 15:18:35 +0000 | [diff] [blame] | 818 | 'M\t.gitignore\n'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 819 | ((['git', 'config', 'branch.master.rietveldpatchset'],), CERR1), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 820 | ((['git', 'log', '--pretty=format:%s%n%n%b', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 821 | 'fake_ancestor_sha...'],), |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 822 | 'foo'), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 823 | ((['git', 'config', 'user.email'],), 'me@example.com'), |
iannucci@chromium.org | 7954005 | 2012-10-19 23:15:26 +0000 | [diff] [blame] | 824 | stat_call, |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 825 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 826 | 'fake_ancestor_sha..HEAD'],), |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 827 | 'desc\n'), |
Aaron Gable | 3a16ed1 | 2017-03-23 10:51:55 -0700 | [diff] [blame] | 828 | ((['git', 'config', 'rietveld.bug-prefix'],), ''), |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 829 | ] |
| 830 | |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 831 | @classmethod |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 832 | def _git_upload_calls(cls, private, no_autocc): |
| 833 | if private or no_autocc: |
tyoshino@chromium.org | 99918ab | 2013-09-30 06:17:28 +0000 | [diff] [blame] | 834 | cc_call = [] |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 835 | else: |
tyoshino@chromium.org | 99918ab | 2013-09-30 06:17:28 +0000 | [diff] [blame] | 836 | cc_call = [((['git', 'config', 'rietveld.cc'],), '')] |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 837 | |
| 838 | if private: |
| 839 | private_call = [] |
| 840 | else: |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 841 | private_call = [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 842 | ((['git', 'config', 'rietveld.private'],), '')] |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 843 | |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 844 | return [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 845 | ((['git', 'config', 'core.editor'],), ''), |
tyoshino@chromium.org | 99918ab | 2013-09-30 06:17:28 +0000 | [diff] [blame] | 846 | ] + cc_call + private_call + [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 847 | ((['git', 'config', 'branch.master.base-url'],), ''), |
Aaron Gable | 1bc7bfe | 2016-12-19 10:08:14 -0800 | [diff] [blame] | 848 | ((['git', 'config', 'remote.origin.url'],), ''), |
sheyang@chromium.org | 152cf83 | 2014-06-11 21:37:49 +0000 | [diff] [blame] | 849 | ((['git', 'config', 'rietveld.project'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 850 | ((['git', 'config', 'branch.master.rietveldissue', '1'],), ''), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 851 | ((['git', 'config', 'branch.master.rietveldserver', |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 852 | 'https://codereview.example.com'],), ''), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 853 | ((['git', |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 854 | 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
tandrii@chromium.org | 1e67bb7 | 2016-02-11 12:15:49 +0000 | [diff] [blame] | 855 | ] + cls._git_post_upload_calls() |
| 856 | |
| 857 | @classmethod |
| 858 | def _git_post_upload_calls(cls): |
| 859 | return [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 860 | ((['git', 'rev-parse', 'HEAD'],), 'hash'), |
| 861 | ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), |
| 862 | ((['git', |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 863 | 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), |
rmistry@google.com | 5626a92 | 2015-02-26 14:03:30 +0000 | [diff] [blame] | 864 | ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 865 | ] |
| 866 | |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 867 | @staticmethod |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 868 | def _git_sanity_checks(diff_base, working_branch, get_remote_branch=True): |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 869 | fake_ancestor = 'fake_ancestor' |
| 870 | fake_cl = 'fake_cl_for_patch' |
| 871 | return [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 872 | ((['git', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 873 | 'rev-parse', '--verify', diff_base],), fake_ancestor), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 874 | ((['git', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 875 | 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 876 | ((['git', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 877 | 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 878 | # Mock a config miss (error code 1) |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 879 | ((['git', |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 880 | 'config', 'gitcl.remotebranch'],), CERR1), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 881 | ] + ([ |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 882 | # Call to GetRemoteBranch() |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 883 | ((['git', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 884 | 'config', 'branch.%s.merge' % working_branch],), |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 885 | 'refs/heads/master'), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 886 | ((['git', |
bratell@opera.com | f267b0e | 2013-05-02 09:11:43 +0000 | [diff] [blame] | 887 | 'config', 'branch.%s.remote' % working_branch],), 'origin'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 888 | ] if get_remote_branch else []) + [ |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 889 | ((['git', 'rev-list', '^' + fake_ancestor, |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 890 | 'refs/remotes/origin/master'],), ''), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 891 | ] |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 892 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 893 | @staticmethod |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 894 | def _cmd_line(description, args, private, cc): |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 895 | """Returns the upload command line passed to upload.RealMain().""" |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 896 | return [ |
Daniel Cheng | 7227d21 | 2017-11-17 08:12:37 -0800 | [diff] [blame] | 897 | 'upload', '--assume_yes', '--server', 'https://codereview.example.com', |
maruel@chromium.org | 71e12a9 | 2012-02-14 02:34:15 +0000 | [diff] [blame] | 898 | '--message', description |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 899 | ] + args + [ |
Daniel Cheng | 7227d21 | 2017-11-17 08:12:37 -0800 | [diff] [blame] | 900 | '--cc', |
| 901 | ','.join( |
| 902 | ['joe@example.com', 'chromium-reviews+test-more-cc@chromium.org'] + |
| 903 | cc), |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 904 | ] + (['--private'] if private else []) + ['fake_ancestor_sha', 'HEAD'] |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 905 | |
| 906 | def _run_reviewer_test( |
| 907 | self, |
| 908 | upload_args, |
| 909 | expected_description, |
| 910 | returned_description, |
| 911 | final_description, |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 912 | reviewers, |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 913 | cc=None): |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 914 | """Generic reviewer test framework.""" |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 915 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
iannucci@chromium.org | 7954005 | 2012-10-19 23:15:26 +0000 | [diff] [blame] | 916 | |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 917 | private = '--private' in upload_args |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 918 | cc = cc or [] |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 919 | no_autocc = '--no-autocc' in upload_args |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 920 | |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 921 | self.calls = self._upload_calls(private, no_autocc) |
pgervais@chromium.org | 87884cc | 2014-01-03 22:23:41 +0000 | [diff] [blame] | 922 | |
jbroman@chromium.org | 615a262 | 2013-05-03 13:20:14 +0000 | [diff] [blame] | 923 | def RunEditor(desc, _, **kwargs): |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 924 | self.assertEquals( |
| 925 | '# Enter a description of the change.\n' |
janx@chromium.org | 104b2db | 2013-04-18 12:58:40 +0000 | [diff] [blame] | 926 | '# This will be displayed on the codereview site.\n' |
alancutter@chromium.org | 63a4d7f | 2013-05-31 02:22:45 +0000 | [diff] [blame] | 927 | '# The first line will also be used as the subject of the review.\n' |
alancutter@chromium.org | bd1073e | 2013-06-01 00:34:38 +0000 | [diff] [blame] | 928 | '#--------------------This line is 72 characters long' |
| 929 | '--------------------\n' + |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 930 | expected_description, |
| 931 | desc) |
| 932 | return returned_description |
| 933 | self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
pgervais@chromium.org | 87884cc | 2014-01-03 22:23:41 +0000 | [diff] [blame] | 934 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 935 | def check_upload(args): |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 936 | cmd_line = self._cmd_line(final_description, reviewers, private, cc) |
iannucci@chromium.org | 53937ba | 2012-10-02 18:20:43 +0000 | [diff] [blame] | 937 | self.assertEquals(cmd_line, args) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 938 | return 1, 2 |
| 939 | self.mock(git_cl.upload, 'RealMain', check_upload) |
pgervais@chromium.org | 87884cc | 2014-01-03 22:23:41 +0000 | [diff] [blame] | 940 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 941 | git_cl.main(['upload'] + upload_args) |
| 942 | |
| 943 | def test_no_reviewer(self): |
| 944 | self._run_reviewer_test( |
| 945 | [], |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 946 | 'desc\n\nBUG=', |
| 947 | '# Blah blah comment.\ndesc\n\nBUG=', |
| 948 | 'desc\n\nBUG=', |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 949 | []) |
| 950 | |
tyoshino@chromium.org | c1737d0 | 2013-05-29 14:17:28 +0000 | [diff] [blame] | 951 | def test_private(self): |
| 952 | self._run_reviewer_test( |
| 953 | ['--private'], |
| 954 | 'desc\n\nBUG=', |
| 955 | '# Blah blah comment.\ndesc\n\nBUG=\n', |
| 956 | 'desc\n\nBUG=', |
| 957 | []) |
| 958 | |
Sergiy Byelozyorov | 1aa405f | 2018-09-18 17:38:43 +0000 | [diff] [blame] | 959 | def test_no_autocc(self): |
| 960 | self._run_reviewer_test( |
| 961 | ['--no-autocc'], |
| 962 | 'desc\n\nBUG=', |
| 963 | '# Blah blah comment.\ndesc\n\nBUG=\n', |
| 964 | 'desc\n\nBUG=', |
| 965 | []) |
| 966 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 967 | def test_reviewers_cmd_line(self): |
| 968 | # Reviewer is passed as-is |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 969 | description = 'desc\n\nR=foo@example.com\nBUG=' |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 970 | self._run_reviewer_test( |
| 971 | ['-r' 'foo@example.com'], |
| 972 | description, |
| 973 | '\n%s\n' % description, |
| 974 | description, |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 975 | ['--reviewers=foo@example.com']) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 976 | |
| 977 | def test_reviewer_tbr_overriden(self): |
| 978 | # Reviewer is overriden with TBR |
| 979 | # Also verifies the regexp work without a trailing LF |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 980 | description = 'Foo Bar\n\nTBR=reviewer@example.com' |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 981 | self._run_reviewer_test( |
| 982 | ['-r' 'foo@example.com'], |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 983 | 'desc\n\nR=foo@example.com\nBUG=', |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 984 | description.strip('\n'), |
| 985 | description, |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 986 | ['--reviewers=reviewer@example.com']) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 987 | |
| 988 | def test_reviewer_multiple(self): |
| 989 | # Handles multiple R= or TBR= lines. |
| 990 | description = ( |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 991 | 'Foo Bar\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' |
| 992 | 'CC=more@example.com,people@example.com') |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 993 | self._run_reviewer_test( |
| 994 | [], |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 995 | 'desc\n\nBUG=', |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 996 | description, |
| 997 | description, |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 998 | ['--reviewers=another@example.com,reviewer@example.com'], |
| 999 | cc=['more@example.com', 'people@example.com']) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 1000 | |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 1001 | def test_reviewer_send_mail(self): |
| 1002 | # --send-mail can be used without -r if R= is used |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1003 | description = 'Foo Bar\nR=reviewer@example.com' |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 1004 | self._run_reviewer_test( |
| 1005 | ['--send-mail'], |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1006 | 'desc\n\nBUG=', |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 1007 | description.strip('\n'), |
| 1008 | description, |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1009 | ['--reviewers=reviewer@example.com', '--send_mail']) |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 1010 | |
| 1011 | def test_reviewer_send_mail_no_rev(self): |
| 1012 | # Fails without a reviewer. |
maruel@chromium.org | 2e23ce3 | 2013-05-07 12:42:28 +0000 | [diff] [blame] | 1013 | stdout = StringIO.StringIO() |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 1014 | self.calls = self._rietveld_upload_no_rev_calls() + [ |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 1015 | ((['DieWithError', 'Must specify reviewers to send email.'],), |
| 1016 | SystemExitMock()) |
| 1017 | ] |
| 1018 | |
| 1019 | def RunEditor(desc, _, **kwargs): |
| 1020 | return desc |
| 1021 | self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
| 1022 | self.mock(sys, 'stdout', stdout) |
| 1023 | with self.assertRaises(SystemExitMock): |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 1024 | git_cl.main(['upload', '--send-mail']) |
Aaron Gable | c4c40d1 | 2017-05-22 11:49:53 -0700 | [diff] [blame] | 1025 | self.assertEqual( |
| 1026 | '=====================================\n' |
| 1027 | 'NOTICE: Rietveld is being deprecated. ' |
| 1028 | 'You can upload changes to Gerrit with\n' |
| 1029 | ' git cl upload --gerrit\n' |
| 1030 | 'or set Gerrit to be your default code review tool with\n' |
| 1031 | ' git config gerrit.host true\n' |
| 1032 | '=====================================\n', |
| 1033 | stdout.getvalue()) |
maruel@chromium.org | a335365 | 2011-11-30 14:26:57 +0000 | [diff] [blame] | 1034 | |
tandrii | f9aefb7 | 2016-07-01 09:06:51 -0700 | [diff] [blame] | 1035 | def test_bug_on_cmd(self): |
| 1036 | self._run_reviewer_test( |
| 1037 | ['--bug=500658,proj:123'], |
| 1038 | 'desc\n\nBUG=500658\nBUG=proj:123', |
| 1039 | '# Blah blah comment.\ndesc\n\nBUG=500658\nBUG=proj:1234', |
| 1040 | 'desc\n\nBUG=500658\nBUG=proj:1234', |
| 1041 | []) |
| 1042 | |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 1043 | @classmethod |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 1044 | def _gerrit_ensure_auth_calls(cls, issue=None, skip_auth_check=False): |
shinyak@chromium.org | 00dbccd | 2016-04-15 07:24:43 +0000 | [diff] [blame] | 1045 | cmd = ['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated'] |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 1046 | if skip_auth_check: |
| 1047 | return [((cmd, ), 'true')] |
| 1048 | |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1049 | calls = [((cmd, ), CERR1)] |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1050 | if issue: |
| 1051 | calls.extend([ |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1052 | ((['git', 'config', 'branch.master.gerritserver'],), CERR1), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1053 | ]) |
| 1054 | calls.extend([ |
| 1055 | ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'), |
| 1056 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 1057 | ((['git', 'config', 'remote.origin.url'],), |
| 1058 | 'https://chromium.googlesource.com/my/repo'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1059 | ]) |
| 1060 | return calls |
| 1061 | |
| 1062 | @classmethod |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1063 | def _gerrit_base_calls(cls, issue=None, fetched_description=None, |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1064 | fetched_status=None, other_cl_owner=None, |
| 1065 | custom_cl_base=None): |
Aaron Gable | 13101a6 | 2018-02-09 13:20:41 -0800 | [diff] [blame] | 1066 | calls = cls._is_gerrit_calls(True) |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1067 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1068 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 1069 | ((['git', 'config', 'branch.master.rietveldissue'],), CERR1), |
| 1070 | ((['git', 'config', 'branch.master.gerritissue'],), |
| 1071 | CERR1 if issue is None else str(issue)), |
| 1072 | ] |
| 1073 | |
| 1074 | if custom_cl_base: |
| 1075 | ancestor_revision = custom_cl_base |
| 1076 | else: |
| 1077 | # Determine ancestor_revision to be merge base. |
| 1078 | ancestor_revision = 'fake_ancestor_sha' |
| 1079 | calls += [ |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1080 | ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'), |
bratell@opera.com | 82b91cd | 2013-07-09 06:33:41 +0000 | [diff] [blame] | 1081 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1082 | ((['get_or_create_merge_base', 'master', |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1083 | 'refs/remotes/origin/master'],), ancestor_revision), |
| 1084 | ] |
| 1085 | |
| 1086 | # Calls to verify branch point is ancestor |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1087 | calls += cls._gerrit_ensure_auth_calls(issue=issue) |
| 1088 | |
| 1089 | if issue: |
| 1090 | calls += [ |
Andrii Shyshkalov | 3e63142 | 2017-02-16 17:46:44 +0100 | [diff] [blame] | 1091 | (('GetChangeDetail', 'chromium-review.googlesource.com', |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 1092 | 'my%2Frepo~123456', |
Andrii Shyshkalov | c4a7356 | 2018-09-25 18:40:17 +0000 | [diff] [blame] | 1093 | ['DETAILED_ACCOUNTS', 'CURRENT_REVISION', 'CURRENT_COMMIT', 'LABELS'] |
| 1094 | ), |
Andrii Shyshkalov | 3e63142 | 2017-02-16 17:46:44 +0100 | [diff] [blame] | 1095 | { |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1096 | 'owner': {'email': (other_cl_owner or 'owner@example.com')}, |
Andrii Shyshkalov | 3e63142 | 2017-02-16 17:46:44 +0100 | [diff] [blame] | 1097 | 'change_id': '123456789', |
| 1098 | 'current_revision': 'sha1_of_current_revision', |
| 1099 | 'revisions': { 'sha1_of_current_revision': { |
| 1100 | 'commit': {'message': fetched_description}, |
| 1101 | }}, |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1102 | 'status': fetched_status or 'NEW', |
Andrii Shyshkalov | 3e63142 | 2017-02-16 17:46:44 +0100 | [diff] [blame] | 1103 | }), |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1104 | ] |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1105 | if fetched_status == 'ABANDONED': |
| 1106 | calls += [ |
| 1107 | (('DieWithError', 'Change https://chromium-review.googlesource.com/' |
| 1108 | '123456 has been abandoned, new uploads are not ' |
| 1109 | 'allowed'), SystemExitMock()), |
| 1110 | ] |
| 1111 | return calls |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1112 | if other_cl_owner: |
| 1113 | calls += [ |
| 1114 | (('ask_for_data', 'Press Enter to upload, or Ctrl+C to abort'), ''), |
| 1115 | ] |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1116 | |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1117 | calls += cls._git_sanity_checks(ancestor_revision, 'master', |
| 1118 | get_remote_branch=False) |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1119 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1120 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 1121 | ((['git', 'rev-parse', 'HEAD'],), '12345'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1122 | |
Aaron Gable | 7817f02 | 2017-12-12 09:43:17 -0800 | [diff] [blame] | 1123 | ((['git', '-c', 'core.quotePath=false', 'diff', '--name-status', |
| 1124 | '--no-renames', '-r', ancestor_revision + '...', '.'],), |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1125 | 'M\t.gitignore\n'), |
| 1126 | ((['git', 'config', 'branch.master.gerritpatchset'],), CERR1), |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1127 | ] |
| 1128 | |
| 1129 | if not issue: |
| 1130 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1131 | ((['git', 'log', '--pretty=format:%s%n%n%b', |
| 1132 | ancestor_revision + '...'],), |
ilevy@chromium.org | 0f58fa8 | 2012-11-05 01:45:20 +0000 | [diff] [blame] | 1133 | 'foo'), |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1134 | ] |
| 1135 | |
| 1136 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1137 | ((['git', 'config', 'user.email'],), 'me@example.com'), |
| 1138 | ((['git', 'diff', '--no-ext-diff', '--stat', '-l100000', '-C50'] + |
| 1139 | ([custom_cl_base] if custom_cl_base else |
| 1140 | [ancestor_revision, 'HEAD']),), |
| 1141 | '+dat'), |
Andrii Shyshkalov | 0293956 | 2017-02-16 17:47:17 +0100 | [diff] [blame] | 1142 | ] |
| 1143 | return calls |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1144 | |
tandrii@chromium.org | 1e67bb7 | 2016-02-11 12:15:49 +0000 | [diff] [blame] | 1145 | @classmethod |
| 1146 | def _gerrit_upload_calls(cls, description, reviewers, squash, |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1147 | squash_mode='default', |
tandrii@chromium.org | 1062500 | 2016-03-04 20:03:47 +0000 | [diff] [blame] | 1148 | expected_upstream_ref='origin/refs/heads/master', |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1149 | title=None, notify=False, |
Andrii Shyshkalov | e9c78ff | 2017-02-06 15:53:13 +0100 | [diff] [blame] | 1150 | post_amend_description=None, issue=None, cc=None, |
Andrii Shyshkalov | 81db1d5 | 2018-08-23 02:17:41 +0000 | [diff] [blame] | 1151 | custom_cl_base=None, tbr=None): |
tandrii@chromium.org | 1062500 | 2016-03-04 20:03:47 +0000 | [diff] [blame] | 1152 | if post_amend_description is None: |
| 1153 | post_amend_description = description |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 1154 | cc = cc or [] |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1155 | # Determined in `_gerrit_base_calls`. |
| 1156 | determined_ancestor_revision = custom_cl_base or 'fake_ancestor_sha' |
| 1157 | |
| 1158 | calls = [] |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1159 | |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1160 | if squash_mode == 'default': |
| 1161 | calls.extend([ |
| 1162 | ((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), ''), |
| 1163 | ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), ''), |
| 1164 | ]) |
| 1165 | elif squash_mode in ('override_squash', 'override_nosquash'): |
| 1166 | calls.extend([ |
| 1167 | ((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), |
| 1168 | 'true' if squash_mode == 'override_squash' else 'false'), |
| 1169 | ]) |
| 1170 | else: |
| 1171 | assert squash_mode in ('squash', 'nosquash') |
| 1172 | |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1173 | # If issue is given, then description is fetched from Gerrit instead. |
| 1174 | if issue is None: |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1175 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1176 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 1177 | ((custom_cl_base + '..') if custom_cl_base else |
| 1178 | 'fake_ancestor_sha..HEAD')],), |
| 1179 | description), |
| 1180 | ] |
Aaron Gable | b56ad33 | 2017-01-06 15:24:31 -0800 | [diff] [blame] | 1181 | if squash: |
Andrii Shyshkalov | febbae9 | 2017-04-05 15:05:20 +0000 | [diff] [blame] | 1182 | title = 'Initial_upload' |
Aaron Gable | b56ad33 | 2017-01-06 15:24:31 -0800 | [diff] [blame] | 1183 | else: |
| 1184 | if not title: |
| 1185 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1186 | ((['git', 'show', '-s', '--format=%s', 'HEAD'],), ''), |
| 1187 | (('ask_for_data', 'Title for patchset []: '), 'User input'), |
Aaron Gable | b56ad33 | 2017-01-06 15:24:31 -0800 | [diff] [blame] | 1188 | ] |
Andrii Shyshkalov | febbae9 | 2017-04-05 15:05:20 +0000 | [diff] [blame] | 1189 | title = 'User_input' |
tandrii@chromium.org | 57d8654 | 2016-03-04 16:11:32 +0000 | [diff] [blame] | 1190 | if not git_footers.get_footer_change_id(description) and not squash: |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1191 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1192 | (('DownloadGerritHook', False), ''), |
| 1193 | # Amending of commit message to get the Change-Id. |
| 1194 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 1195 | determined_ancestor_revision + '..HEAD'],), |
| 1196 | description), |
| 1197 | ((['git', 'commit', '--amend', '-m', description],), ''), |
| 1198 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
| 1199 | determined_ancestor_revision + '..HEAD'],), |
| 1200 | post_amend_description) |
| 1201 | ] |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1202 | if squash: |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1203 | if not issue: |
| 1204 | # Prompting to edit description on first upload. |
| 1205 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1206 | ((['git', 'config', 'core.editor'],), ''), |
| 1207 | ((['RunEditor'],), description), |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1208 | ] |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1209 | ref_to_push = 'abcdef0123456789' |
| 1210 | calls += [ |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1211 | ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'), |
| 1212 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 1213 | ] |
| 1214 | |
| 1215 | if custom_cl_base is None: |
| 1216 | calls += [ |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1217 | ((['get_or_create_merge_base', 'master', |
| 1218 | 'refs/remotes/origin/master'],), |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1219 | 'origin/master'), |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1220 | ] |
| 1221 | parent = 'origin/master' |
| 1222 | else: |
| 1223 | calls += [ |
| 1224 | ((['git', 'merge-base', '--is-ancestor', custom_cl_base, |
| 1225 | 'refs/remotes/origin/master'],), |
| 1226 | callError(1)), # Means not ancenstor. |
| 1227 | (('ask_for_data', |
| 1228 | 'Do you take responsibility for cleaning up potential mess ' |
| 1229 | 'resulting from proceeding with upload? Press Enter to upload, ' |
| 1230 | 'or Ctrl+C to abort'), ''), |
| 1231 | ] |
| 1232 | parent = custom_cl_base |
| 1233 | |
| 1234 | calls += [ |
| 1235 | ((['git', 'rev-parse', 'HEAD:'],), # `HEAD:` means HEAD's tree hash. |
| 1236 | '0123456789abcdef'), |
| 1237 | ((['git', 'commit-tree', '0123456789abcdef', '-p', parent, |
Aaron Gable | 9a03ae0 | 2017-11-03 11:31:07 -0700 | [diff] [blame] | 1238 | '-F', '/tmp/named'],), |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1239 | ref_to_push), |
| 1240 | ] |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1241 | else: |
| 1242 | ref_to_push = 'HEAD' |
| 1243 | |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1244 | calls += [ |
Andrii Shyshkalov | d9fdc1f | 2018-09-27 02:13:09 +0000 | [diff] [blame^] | 1245 | (('SaveDescriptionBackup',), None), |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1246 | ((['git', 'rev-list', |
| 1247 | (custom_cl_base if custom_cl_base else expected_upstream_ref) + '..' + |
| 1248 | ref_to_push],), |
| 1249 | '1hashPerLine\n'), |
| 1250 | ] |
tandrii@chromium.org | 8da4540 | 2016-05-24 23:11:03 +0000 | [diff] [blame] | 1251 | |
Aaron Gable | afd5277 | 2017-06-27 16:40:10 -0700 | [diff] [blame] | 1252 | if notify: |
Aaron Gable | 844cf29 | 2017-06-28 11:32:59 -0700 | [diff] [blame] | 1253 | ref_suffix = '%ready,notify=ALL' |
| 1254 | else: |
Jamie Madill | 276da0b | 2018-04-27 14:41:20 -0400 | [diff] [blame] | 1255 | if not issue and squash: |
Aaron Gable | 844cf29 | 2017-06-28 11:32:59 -0700 | [diff] [blame] | 1256 | ref_suffix = '%wip' |
| 1257 | else: |
| 1258 | ref_suffix = '%notify=NONE' |
Aaron Gable | 9b713dd | 2016-12-14 16:04:21 -0800 | [diff] [blame] | 1259 | |
Aaron Gable | 70f4e24 | 2017-06-26 10:45:59 -0700 | [diff] [blame] | 1260 | if title: |
Aaron Gable | afd5277 | 2017-06-27 16:40:10 -0700 | [diff] [blame] | 1261 | ref_suffix += ',m=' + title |
Andrii Shyshkalov | febbae9 | 2017-04-05 15:05:20 +0000 | [diff] [blame] | 1262 | |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1263 | calls.append(( |
| 1264 | (['git', 'push', |
Andrii Shyshkalov | 81db1d5 | 2018-08-23 02:17:41 +0000 | [diff] [blame] | 1265 | 'https://chromium.googlesource.com/my/repo', |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1266 | ref_to_push + ':refs/for/refs/heads/master' + ref_suffix],), |
| 1267 | ('remote:\n' |
| 1268 | 'remote: Processing changes: (\)\n' |
| 1269 | 'remote: Processing changes: (|)\n' |
| 1270 | 'remote: Processing changes: (/)\n' |
| 1271 | 'remote: Processing changes: (-)\n' |
| 1272 | 'remote: Processing changes: new: 1 (/)\n' |
| 1273 | 'remote: Processing changes: new: 1, done\n' |
| 1274 | 'remote:\n' |
| 1275 | 'remote: New Changes:\n' |
Andrii Shyshkalov | 81db1d5 | 2018-08-23 02:17:41 +0000 | [diff] [blame] | 1276 | 'remote: https://chromium-review.googlesource.com/#/c/my/repo/+/123456' |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1277 | ' XXX\n' |
| 1278 | 'remote:\n' |
Andrii Shyshkalov | 81db1d5 | 2018-08-23 02:17:41 +0000 | [diff] [blame] | 1279 | 'To https://chromium.googlesource.com/my/repo\n' |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1280 | ' * [new branch] hhhh -> refs/for/refs/heads/master\n') |
| 1281 | )) |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1282 | if squash: |
| 1283 | calls += [ |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1284 | ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1285 | ''), |
tandrii@chromium.org | aa5ced1 | 2016-03-29 09:41:14 +0000 | [diff] [blame] | 1286 | ((['git', 'config', 'branch.master.gerritserver', |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1287 | 'https://chromium-review.googlesource.com'],), ''), |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1288 | ((['git', 'config', 'branch.master.gerritsquashhash', |
| 1289 | 'abcdef0123456789'],), ''), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 1290 | ] |
tandrii | 8818977 | 2016-09-29 04:29:57 -0700 | [diff] [blame] | 1291 | calls += [ |
| 1292 | ((['git', 'config', 'rietveld.cc'],), ''), |
tandrii | 8818977 | 2016-09-29 04:29:57 -0700 | [diff] [blame] | 1293 | ] |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1294 | if squash: |
| 1295 | calls += [ |
| 1296 | (('AddReviewers', |
Andrii Shyshkalov | 1e82867 | 2018-08-23 22:34:37 +0000 | [diff] [blame] | 1297 | 'chromium-review.googlesource.com', 'my%2Frepo~123456', |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1298 | sorted(reviewers), |
| 1299 | ['joe@example.com', 'chromium-reviews+test-more-cc@chromium.org'] + |
| 1300 | cc, notify), ''), |
| 1301 | ] |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1302 | if tbr: |
| 1303 | calls += [ |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 1304 | (('GetChangeDetail', 'chromium-review.googlesource.com', |
| 1305 | 'my%2Frepo~123456', ['LABELS']), { |
Yoshisato Yanagisawa | 81e3ff5 | 2017-09-26 15:33:34 +0900 | [diff] [blame] | 1306 | 'labels': { |
| 1307 | 'Code-Review': { |
| 1308 | 'default_value': 0, |
| 1309 | 'all': [], |
| 1310 | 'values': { |
| 1311 | '+2': 'lgtm, approved', |
| 1312 | '+1': 'lgtm, but someone else must approve', |
| 1313 | ' 0': 'No score', |
| 1314 | '-1': 'Don\'t submit as-is', |
| 1315 | } |
| 1316 | } |
| 1317 | } |
| 1318 | }), |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1319 | (('SetReview', |
| 1320 | 'chromium-review.googlesource.com', |
Andrii Shyshkalov | 1e82867 | 2018-08-23 22:34:37 +0000 | [diff] [blame] | 1321 | 'my%2Frepo~123456', |
Andrii Shyshkalov | 0ec9d15 | 2018-08-23 00:22:58 +0000 | [diff] [blame] | 1322 | 'Self-approving for TBR', |
Yoshisato Yanagisawa | 81e3ff5 | 2017-09-26 15:33:34 +0900 | [diff] [blame] | 1323 | {'Code-Review': 2}, None), ''), |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1324 | ] |
tandrii@chromium.org | 1e67bb7 | 2016-02-11 12:15:49 +0000 | [diff] [blame] | 1325 | calls += cls._git_post_upload_calls() |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1326 | return calls |
| 1327 | |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1328 | def _run_gerrit_upload_test( |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1329 | self, |
| 1330 | upload_args, |
| 1331 | description, |
tandrii@chromium.org | bf766ba | 2016-04-13 12:51:23 +0000 | [diff] [blame] | 1332 | reviewers=None, |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1333 | squash=True, |
| 1334 | squash_mode=None, |
tandrii@chromium.org | 1062500 | 2016-03-04 20:03:47 +0000 | [diff] [blame] | 1335 | expected_upstream_ref='origin/refs/heads/master', |
Aaron Gable | 9b713dd | 2016-12-14 16:04:21 -0800 | [diff] [blame] | 1336 | title=None, |
tandrii@chromium.org | 8da4540 | 2016-05-24 23:11:03 +0000 | [diff] [blame] | 1337 | notify=False, |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1338 | post_amend_description=None, |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 1339 | issue=None, |
Andrii Shyshkalov | e9c78ff | 2017-02-06 15:53:13 +0100 | [diff] [blame] | 1340 | cc=None, |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1341 | fetched_status=None, |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1342 | other_cl_owner=None, |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1343 | custom_cl_base=None, |
| 1344 | tbr=None): |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1345 | """Generic gerrit upload test framework.""" |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1346 | if squash_mode is None: |
| 1347 | if '--no-squash' in upload_args: |
| 1348 | squash_mode = 'nosquash' |
| 1349 | elif '--squash' in upload_args: |
| 1350 | squash_mode = 'squash' |
| 1351 | else: |
| 1352 | squash_mode = 'default' |
| 1353 | |
tandrii@chromium.org | bf766ba | 2016-04-13 12:51:23 +0000 | [diff] [blame] | 1354 | reviewers = reviewers or [] |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 1355 | cc = cc or [] |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 1356 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
tandrii | 16e0b4e | 2016-06-07 10:34:28 -0700 | [diff] [blame] | 1357 | self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1358 | CookiesAuthenticatorMockFactory( |
| 1359 | same_auth=('git-owner.example.com', '', 'pass'))) |
tandrii | 16e0b4e | 2016-06-07 10:34:28 -0700 | [diff] [blame] | 1360 | self.mock(git_cl._GerritChangelistImpl, '_GerritCommitMsgHookCheck', |
| 1361 | lambda _, offer_removal: None) |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1362 | self.mock(git_cl.gclient_utils, 'RunEditor', |
| 1363 | lambda *_, **__: self._mocked_call(['RunEditor'])) |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1364 | self.mock(git_cl, 'DownloadGerritHook', lambda force: self._mocked_call( |
| 1365 | 'DownloadGerritHook', force)) |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1366 | |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1367 | self.calls = self._gerrit_base_calls( |
| 1368 | issue=issue, |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1369 | fetched_description=description, |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1370 | fetched_status=fetched_status, |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1371 | other_cl_owner=other_cl_owner, |
| 1372 | custom_cl_base=custom_cl_base) |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1373 | if fetched_status != 'ABANDONED': |
Aaron Gable | 9a03ae0 | 2017-11-03 11:31:07 -0700 | [diff] [blame] | 1374 | self.mock(tempfile, 'NamedTemporaryFile', MakeNamedTemporaryFileMock( |
| 1375 | expected_content=description)) |
| 1376 | self.mock(os, 'remove', lambda _: True) |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1377 | self.calls += self._gerrit_upload_calls( |
| 1378 | description, reviewers, squash, |
| 1379 | squash_mode=squash_mode, |
| 1380 | expected_upstream_ref=expected_upstream_ref, |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1381 | title=title, notify=notify, |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1382 | post_amend_description=post_amend_description, |
Andrii Shyshkalov | 81db1d5 | 2018-08-23 02:17:41 +0000 | [diff] [blame] | 1383 | issue=issue, cc=cc, |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1384 | custom_cl_base=custom_cl_base, tbr=tbr) |
tandrii@chromium.org | 09d7a6a | 2016-03-04 15:44:48 +0000 | [diff] [blame] | 1385 | # Uncomment when debugging. |
| 1386 | # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1387 | git_cl.main(['upload'] + upload_args) |
| 1388 | |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1389 | def test_gerrit_upload_without_change_id(self): |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1390 | self._run_gerrit_upload_test( |
| 1391 | ['--no-squash'], |
| 1392 | 'desc\n\nBUG=\n', |
| 1393 | [], |
| 1394 | squash=False, |
| 1395 | post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') |
| 1396 | |
| 1397 | def test_gerrit_upload_without_change_id_override_nosquash(self): |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1398 | self._run_gerrit_upload_test( |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1399 | [], |
jamesr@chromium.org | 35d1a84 | 2012-07-27 00:20:43 +0000 | [diff] [blame] | 1400 | 'desc\n\nBUG=\n', |
tandrii@chromium.org | 1062500 | 2016-03-04 20:03:47 +0000 | [diff] [blame] | 1401 | [], |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1402 | squash=False, |
| 1403 | squash_mode='override_nosquash', |
tandrii@chromium.org | 1062500 | 2016-03-04 20:03:47 +0000 | [diff] [blame] | 1404 | post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1405 | |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1406 | def test_gerrit_no_reviewer(self): |
| 1407 | self._run_gerrit_upload_test( |
| 1408 | [], |
tandrii@chromium.org | 09d7a6a | 2016-03-04 15:44:48 +0000 | [diff] [blame] | 1409 | 'desc\n\nBUG=\n\nChange-Id: I123456789\n', |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1410 | [], |
| 1411 | squash=False, |
| 1412 | squash_mode='override_nosquash') |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1413 | |
Nick Carter | 8692b18 | 2017-11-06 16:30:38 -0800 | [diff] [blame] | 1414 | def test_gerrit_patchset_title_special_chars(self): |
Andrii Shyshkalov | febbae9 | 2017-04-05 15:05:20 +0000 | [diff] [blame] | 1415 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 1416 | self._run_gerrit_upload_test( |
Nick Carter | 8692b18 | 2017-11-06 16:30:38 -0800 | [diff] [blame] | 1417 | ['-f', '-t', 'We\'ll escape ^_ ^ special chars...@{u}'], |
Andrii Shyshkalov | febbae9 | 2017-04-05 15:05:20 +0000 | [diff] [blame] | 1418 | 'desc\n\nBUG=\n\nChange-Id: I123456789', |
| 1419 | squash=False, |
| 1420 | squash_mode='override_nosquash', |
Nick Carter | 8692b18 | 2017-11-06 16:30:38 -0800 | [diff] [blame] | 1421 | title='We%27ll_escape_%5E%5F_%5E_special_chars%2E%2E%2E%40%7Bu%7D') |
Andrii Shyshkalov | febbae9 | 2017-04-05 15:05:20 +0000 | [diff] [blame] | 1422 | |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1423 | def test_gerrit_reviewers_cmd_line(self): |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1424 | self._run_gerrit_upload_test( |
tandrii@chromium.org | 8da4540 | 2016-05-24 23:11:03 +0000 | [diff] [blame] | 1425 | ['-r', 'foo@example.com', '--send-mail'], |
tandrii@chromium.org | 09d7a6a | 2016-03-04 15:44:48 +0000 | [diff] [blame] | 1426 | 'desc\n\nBUG=\n\nChange-Id: I123456789', |
tandrii@chromium.org | 8da4540 | 2016-05-24 23:11:03 +0000 | [diff] [blame] | 1427 | ['foo@example.com'], |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1428 | squash=False, |
| 1429 | squash_mode='override_nosquash', |
tandrii@chromium.org | 8da4540 | 2016-05-24 23:11:03 +0000 | [diff] [blame] | 1430 | notify=True) |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1431 | |
| 1432 | def test_gerrit_reviewer_multiple(self): |
sivachandra@chromium.org | aebe87f | 2012-10-22 20:34:21 +0000 | [diff] [blame] | 1433 | self._run_gerrit_upload_test( |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1434 | [], |
bradnelson | d975b30 | 2016-10-23 12:20:23 -0700 | [diff] [blame] | 1435 | 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' |
| 1436 | 'CC=more@example.com,people@example.com\n\n' |
Yoshisato Yanagisawa | 81e3ff5 | 2017-09-26 15:33:34 +0900 | [diff] [blame] | 1437 | 'Change-Id: 123456789', |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1438 | ['reviewer@example.com', 'another@example.com'], |
Yoshisato Yanagisawa | 81e3ff5 | 2017-09-26 15:33:34 +0900 | [diff] [blame] | 1439 | expected_upstream_ref='origin/master', |
Aaron Gable | fd23808 | 2017-06-07 13:42:34 -0700 | [diff] [blame] | 1440 | cc=['more@example.com', 'people@example.com'], |
| 1441 | tbr='reviewer@example.com') |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1442 | |
| 1443 | def test_gerrit_upload_squash_first_is_default(self): |
tandrii | a60502f | 2016-06-20 02:01:53 -0700 | [diff] [blame] | 1444 | self._run_gerrit_upload_test( |
| 1445 | [], |
| 1446 | 'desc\nBUG=\n\nChange-Id: 123456789', |
| 1447 | [], |
| 1448 | expected_upstream_ref='origin/master') |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1449 | |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1450 | def test_gerrit_upload_squash_first(self): |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1451 | self._run_gerrit_upload_test( |
| 1452 | ['--squash'], |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1453 | 'desc\nBUG=\n\nChange-Id: 123456789', |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1454 | [], |
luqui@chromium.org | 609f395 | 2015-05-04 22:47:04 +0000 | [diff] [blame] | 1455 | squash=True, |
| 1456 | expected_upstream_ref='origin/master') |
ukai@chromium.org | e807781 | 2012-02-03 03:41:46 +0000 | [diff] [blame] | 1457 | |
Andrii Shyshkalov | 550e924 | 2017-04-12 17:14:49 +0200 | [diff] [blame] | 1458 | def test_gerrit_upload_squash_first_against_rev(self): |
| 1459 | custom_cl_base = 'custom_cl_base_rev_or_branch' |
| 1460 | self._run_gerrit_upload_test( |
| 1461 | ['--squash', custom_cl_base], |
| 1462 | 'desc\nBUG=\n\nChange-Id: 123456789', |
| 1463 | [], |
| 1464 | squash=True, |
| 1465 | expected_upstream_ref='origin/master', |
| 1466 | custom_cl_base=custom_cl_base) |
| 1467 | self.assertIn( |
| 1468 | 'If you proceed with upload, more than 1 CL may be created by Gerrit', |
| 1469 | sys.stdout.getvalue()) |
| 1470 | |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1471 | def test_gerrit_upload_squash_reupload(self): |
| 1472 | description = 'desc\nBUG=\n\nChange-Id: 123456789' |
tandrii@chromium.org | 512d79c | 2016-03-31 12:55:28 +0000 | [diff] [blame] | 1473 | self._run_gerrit_upload_test( |
| 1474 | ['--squash'], |
| 1475 | description, |
| 1476 | [], |
| 1477 | squash=True, |
| 1478 | expected_upstream_ref='origin/master', |
| 1479 | issue=123456) |
| 1480 | |
Andrii Shyshkalov | 5c3d0b3 | 2017-02-16 17:47:31 +0100 | [diff] [blame] | 1481 | def test_gerrit_upload_squash_reupload_to_abandoned(self): |
| 1482 | self.mock(git_cl, 'DieWithError', |
| 1483 | lambda msg, change=None: self._mocked_call('DieWithError', msg)) |
| 1484 | description = 'desc\nBUG=\n\nChange-Id: 123456789' |
| 1485 | with self.assertRaises(SystemExitMock): |
| 1486 | self._run_gerrit_upload_test( |
| 1487 | ['--squash'], |
| 1488 | description, |
| 1489 | [], |
| 1490 | squash=True, |
| 1491 | expected_upstream_ref='origin/master', |
| 1492 | issue=123456, |
| 1493 | fetched_status='ABANDONED') |
| 1494 | |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1495 | def test_gerrit_upload_squash_reupload_to_not_owned(self): |
| 1496 | self.mock(git_cl.gerrit_util, 'GetAccountDetails', |
| 1497 | lambda *_, **__: {'email': 'yet-another@example.com'}) |
| 1498 | description = 'desc\nBUG=\n\nChange-Id: 123456789' |
| 1499 | self._run_gerrit_upload_test( |
| 1500 | ['--squash'], |
| 1501 | description, |
| 1502 | [], |
| 1503 | squash=True, |
| 1504 | expected_upstream_ref='origin/master', |
| 1505 | issue=123456, |
| 1506 | other_cl_owner='other@example.com') |
| 1507 | self.assertIn( |
Quinten Yearsley | 0c62da9 | 2017-05-31 13:39:42 -0700 | [diff] [blame] | 1508 | 'WARNING: Change 123456 is owned by other@example.com, but you ' |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 1509 | 'authenticate to Gerrit as yet-another@example.com.\n' |
| 1510 | 'Uploading may fail due to lack of permissions', |
| 1511 | git_cl.sys.stdout.getvalue()) |
| 1512 | |
rmistry@google.com | 2dd9986 | 2015-06-22 12:22:18 +0000 | [diff] [blame] | 1513 | def test_upload_branch_deps(self): |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 1514 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
rmistry@google.com | 2dd9986 | 2015-06-22 12:22:18 +0000 | [diff] [blame] | 1515 | def mock_run_git(*args, **_kwargs): |
| 1516 | if args[0] == ['for-each-ref', |
| 1517 | '--format=%(refname:short) %(upstream:short)', |
| 1518 | 'refs/heads']: |
| 1519 | # Create a local branch dependency tree that looks like this: |
| 1520 | # test1 -> test2 -> test3 -> test4 -> test5 |
| 1521 | # -> test3.1 |
| 1522 | # test6 -> test0 |
| 1523 | branch_deps = [ |
| 1524 | 'test2 test1', # test1 -> test2 |
| 1525 | 'test3 test2', # test2 -> test3 |
| 1526 | 'test3.1 test2', # test2 -> test3.1 |
| 1527 | 'test4 test3', # test3 -> test4 |
| 1528 | 'test5 test4', # test4 -> test5 |
| 1529 | 'test6 test0', # test0 -> test6 |
| 1530 | 'test7', # test7 |
| 1531 | ] |
| 1532 | return '\n'.join(branch_deps) |
| 1533 | self.mock(git_cl, 'RunGit', mock_run_git) |
| 1534 | |
| 1535 | class RecordCalls: |
| 1536 | times_called = 0 |
| 1537 | record_calls = RecordCalls() |
| 1538 | def mock_CMDupload(*args, **_kwargs): |
| 1539 | record_calls.times_called += 1 |
| 1540 | return 0 |
| 1541 | self.mock(git_cl, 'CMDupload', mock_CMDupload) |
| 1542 | |
| 1543 | self.calls = [ |
Andrii Shyshkalov | abc26ac | 2017-03-14 14:49:38 +0100 | [diff] [blame] | 1544 | (('ask_for_data', 'This command will checkout all dependent branches ' |
| 1545 | 'and run "git cl upload". Press Enter to continue, ' |
| 1546 | 'or Ctrl+C to abort'), ''), |
| 1547 | ] |
rmistry@google.com | 2dd9986 | 2015-06-22 12:22:18 +0000 | [diff] [blame] | 1548 | |
| 1549 | class MockChangelist(): |
| 1550 | def __init__(self): |
| 1551 | pass |
| 1552 | def GetBranch(self): |
| 1553 | return 'test1' |
| 1554 | def GetIssue(self): |
| 1555 | return '123' |
| 1556 | def GetPatchset(self): |
| 1557 | return '1001' |
tandrii@chromium.org | 4c72b08 | 2016-03-31 22:26:35 +0000 | [diff] [blame] | 1558 | def IsGerrit(self): |
| 1559 | return False |
rmistry@google.com | 2dd9986 | 2015-06-22 12:22:18 +0000 | [diff] [blame] | 1560 | |
| 1561 | ret = git_cl.upload_branch_deps(MockChangelist(), []) |
| 1562 | # CMDupload should have been called 5 times because of 5 dependent branches. |
| 1563 | self.assertEquals(5, record_calls.times_called) |
| 1564 | self.assertEquals(0, ret) |
| 1565 | |
tandrii@chromium.org | 65874e1 | 2016-03-04 12:03:02 +0000 | [diff] [blame] | 1566 | def test_gerrit_change_id(self): |
| 1567 | self.calls = [ |
| 1568 | ((['git', 'write-tree'], ), |
| 1569 | 'hashtree'), |
| 1570 | ((['git', 'rev-parse', 'HEAD~0'], ), |
| 1571 | 'branch-parent'), |
| 1572 | ((['git', 'var', 'GIT_AUTHOR_IDENT'], ), |
| 1573 | 'A B <a@b.org> 1456848326 +0100'), |
| 1574 | ((['git', 'var', 'GIT_COMMITTER_IDENT'], ), |
| 1575 | 'C D <c@d.org> 1456858326 +0100'), |
| 1576 | ((['git', 'hash-object', '-t', 'commit', '--stdin'], ), |
| 1577 | 'hashchange'), |
| 1578 | ] |
| 1579 | change_id = git_cl.GenerateGerritChangeId('line1\nline2\n') |
| 1580 | self.assertEqual(change_id, 'Ihashchange') |
| 1581 | |
tandrii@chromium.org | 601e1d1 | 2016-06-03 13:03:54 +0000 | [diff] [blame] | 1582 | def test_desecription_append_footer(self): |
| 1583 | for init_desc, footer_line, expected_desc in [ |
| 1584 | # Use unique desc first lines for easy test failure identification. |
| 1585 | ('foo', 'R=one', 'foo\n\nR=one'), |
| 1586 | ('foo\n\nR=one', 'BUG=', 'foo\n\nR=one\nBUG='), |
| 1587 | ('foo\n\nR=one', 'Change-Id: Ixx', 'foo\n\nR=one\n\nChange-Id: Ixx'), |
| 1588 | ('foo\n\nChange-Id: Ixx', 'R=one', 'foo\n\nR=one\n\nChange-Id: Ixx'), |
| 1589 | ('foo\n\nR=one\n\nChange-Id: Ixx', 'TBR=two', |
| 1590 | 'foo\n\nR=one\nTBR=two\n\nChange-Id: Ixx'), |
| 1591 | ('foo\n\nR=one\n\nChange-Id: Ixx', 'Foo-Bar: baz', |
| 1592 | 'foo\n\nR=one\n\nChange-Id: Ixx\nFoo-Bar: baz'), |
| 1593 | ('foo\n\nChange-Id: Ixx', 'Foo-Bak: baz', |
| 1594 | 'foo\n\nChange-Id: Ixx\nFoo-Bak: baz'), |
| 1595 | ('foo', 'Change-Id: Ixx', 'foo\n\nChange-Id: Ixx'), |
| 1596 | ]: |
| 1597 | desc = git_cl.ChangeDescription(init_desc) |
| 1598 | desc.append_footer(footer_line) |
| 1599 | self.assertEqual(desc.description, expected_desc) |
| 1600 | |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1601 | def test_update_reviewers(self): |
| 1602 | data = [ |
Robert Iannucci | 6c98dc6 | 2017-04-18 11:38:00 -0700 | [diff] [blame] | 1603 | ('foo', [], [], |
| 1604 | 'foo'), |
| 1605 | ('foo\nR=xx', [], [], |
| 1606 | 'foo\nR=xx'), |
| 1607 | ('foo\nTBR=xx', [], [], |
| 1608 | 'foo\nTBR=xx'), |
| 1609 | ('foo', ['a@c'], [], |
| 1610 | 'foo\n\nR=a@c'), |
| 1611 | ('foo\nR=xx', ['a@c'], [], |
| 1612 | 'foo\n\nR=a@c, xx'), |
| 1613 | ('foo\nTBR=xx', ['a@c'], [], |
| 1614 | 'foo\n\nR=a@c\nTBR=xx'), |
| 1615 | ('foo\nTBR=xx\nR=yy', ['a@c'], [], |
| 1616 | 'foo\n\nR=a@c, yy\nTBR=xx'), |
| 1617 | ('foo\nBUG=', ['a@c'], [], |
| 1618 | 'foo\nBUG=\nR=a@c'), |
| 1619 | ('foo\nR=xx\nTBR=yy\nR=bar', ['a@c'], [], |
| 1620 | 'foo\n\nR=a@c, bar, xx\nTBR=yy'), |
| 1621 | ('foo', ['a@c', 'b@c'], [], |
| 1622 | 'foo\n\nR=a@c, b@c'), |
| 1623 | ('foo\nBar\n\nR=\nBUG=', ['c@c'], [], |
| 1624 | 'foo\nBar\n\nR=c@c\nBUG='), |
| 1625 | ('foo\nBar\n\nR=\nBUG=\nR=', ['c@c'], [], |
| 1626 | 'foo\nBar\n\nR=c@c\nBUG='), |
maruel@chromium.org | c6f60e8 | 2013-04-19 17:01:57 +0000 | [diff] [blame] | 1627 | # Same as the line before, but full of whitespaces. |
| 1628 | ( |
Robert Iannucci | 6c98dc6 | 2017-04-18 11:38:00 -0700 | [diff] [blame] | 1629 | 'foo\nBar\n\n R = \n BUG = \n R = ', ['c@c'], [], |
maruel@chromium.org | c6f60e8 | 2013-04-19 17:01:57 +0000 | [diff] [blame] | 1630 | 'foo\nBar\n\nR=c@c\n BUG =', |
| 1631 | ), |
| 1632 | # Whitespaces aren't interpreted as new lines. |
Robert Iannucci | 6c98dc6 | 2017-04-18 11:38:00 -0700 | [diff] [blame] | 1633 | ('foo BUG=allo R=joe ', ['c@c'], [], |
| 1634 | 'foo BUG=allo R=joe\n\nR=c@c'), |
| 1635 | # Redundant TBRs get promoted to Rs |
| 1636 | ('foo\n\nR=a@c\nTBR=t@c', ['b@c', 'a@c'], ['a@c', 't@c'], |
| 1637 | 'foo\n\nR=a@c, b@c\nTBR=t@c'), |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1638 | ] |
Robert Iannucci | 6c98dc6 | 2017-04-18 11:38:00 -0700 | [diff] [blame] | 1639 | expected = [i[-1] for i in data] |
maruel@chromium.org | c6f60e8 | 2013-04-19 17:01:57 +0000 | [diff] [blame] | 1640 | actual = [] |
Robert Iannucci | 6c98dc6 | 2017-04-18 11:38:00 -0700 | [diff] [blame] | 1641 | for orig, reviewers, tbrs, _expected in data: |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1642 | obj = git_cl.ChangeDescription(orig) |
Robert Iannucci | 6c98dc6 | 2017-04-18 11:38:00 -0700 | [diff] [blame] | 1643 | obj.update_reviewers(reviewers, tbrs) |
maruel@chromium.org | c6f60e8 | 2013-04-19 17:01:57 +0000 | [diff] [blame] | 1644 | actual.append(obj.description) |
| 1645 | self.assertEqual(expected, actual) |
maruel@chromium.org | 78936cb | 2013-04-11 00:17:52 +0000 | [diff] [blame] | 1646 | |
Nodir Turakulov | 23b8214 | 2017-11-16 11:04:25 -0800 | [diff] [blame] | 1647 | def test_get_hash_tags(self): |
| 1648 | cases = [ |
| 1649 | ('', []), |
| 1650 | ('a', []), |
| 1651 | ('[a]', ['a']), |
| 1652 | ('[aa]', ['aa']), |
| 1653 | ('[a ]', ['a']), |
| 1654 | ('[a- ]', ['a']), |
| 1655 | ('[a- b]', ['a-b']), |
| 1656 | ('[a--b]', ['a-b']), |
| 1657 | ('[a', []), |
| 1658 | ('[a]x', ['a']), |
| 1659 | ('[aa]x', ['aa']), |
| 1660 | ('[a b]', ['a-b']), |
| 1661 | ('[a b]', ['a-b']), |
| 1662 | ('[a__b]', ['a-b']), |
| 1663 | ('[a] x', ['a']), |
| 1664 | ('[a][b]', ['a', 'b']), |
| 1665 | ('[a] [b]', ['a', 'b']), |
| 1666 | ('[a][b]x', ['a', 'b']), |
| 1667 | ('[a][b] x', ['a', 'b']), |
| 1668 | ('[a]\n[b]', ['a']), |
| 1669 | ('[a\nb]', []), |
| 1670 | ('[a][', ['a']), |
| 1671 | ('Revert "[a] feature"', ['a']), |
| 1672 | ('Reland "[a] feature"', ['a']), |
| 1673 | ('Revert: [a] feature', ['a']), |
| 1674 | ('Reland: [a] feature', ['a']), |
| 1675 | ('Revert "Reland: [a] feature"', ['a']), |
| 1676 | ('Foo: feature', ['foo']), |
| 1677 | ('Foo Bar: feature', ['foo-bar']), |
| 1678 | ('Revert "Foo bar: feature"', ['foo-bar']), |
| 1679 | ('Reland "Foo bar: feature"', ['foo-bar']), |
| 1680 | ] |
| 1681 | for desc, expected in cases: |
| 1682 | change_desc = git_cl.ChangeDescription(desc) |
| 1683 | actual = change_desc.get_hash_tags() |
| 1684 | self.assertEqual( |
| 1685 | actual, |
| 1686 | expected, |
| 1687 | 'GetHashTags(%r) == %r, expected %r' % (desc, actual, expected)) |
| 1688 | |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1689 | def test_get_target_ref(self): |
| 1690 | # Check remote or remote branch not present. |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1691 | self.assertEqual(None, git_cl.GetTargetRef('origin', None, 'master')) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1692 | self.assertEqual(None, git_cl.GetTargetRef(None, |
| 1693 | 'refs/remotes/origin/master', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1694 | 'master')) |
bauerb@chromium.org | 27386dd | 2015-02-16 10:45:39 +0000 | [diff] [blame] | 1695 | |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1696 | # Check default target refs for branches. |
| 1697 | self.assertEqual('refs/heads/master', |
| 1698 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1699 | None)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1700 | self.assertEqual('refs/heads/master', |
| 1701 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkgr', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1702 | None)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1703 | self.assertEqual('refs/heads/master', |
| 1704 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkcr', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1705 | None)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1706 | self.assertEqual('refs/branch-heads/123', |
| 1707 | git_cl.GetTargetRef('origin', |
| 1708 | 'refs/remotes/branch-heads/123', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1709 | None)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1710 | self.assertEqual('refs/diff/test', |
| 1711 | git_cl.GetTargetRef('origin', |
| 1712 | 'refs/remotes/origin/refs/diff/test', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1713 | None)) |
rmistry@google.com | c68112d | 2015-03-03 12:48:06 +0000 | [diff] [blame] | 1714 | self.assertEqual('refs/heads/chrome/m42', |
| 1715 | git_cl.GetTargetRef('origin', |
| 1716 | 'refs/remotes/origin/chrome/m42', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1717 | None)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1718 | |
| 1719 | # Check target refs for user-specified target branch. |
| 1720 | for branch in ('branch-heads/123', 'remotes/branch-heads/123', |
| 1721 | 'refs/remotes/branch-heads/123'): |
| 1722 | self.assertEqual('refs/branch-heads/123', |
| 1723 | git_cl.GetTargetRef('origin', |
| 1724 | 'refs/remotes/origin/master', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1725 | branch)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1726 | for branch in ('origin/master', 'remotes/origin/master', |
| 1727 | 'refs/remotes/origin/master'): |
| 1728 | self.assertEqual('refs/heads/master', |
| 1729 | git_cl.GetTargetRef('origin', |
| 1730 | 'refs/remotes/branch-heads/123', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1731 | branch)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1732 | for branch in ('master', 'heads/master', 'refs/heads/master'): |
| 1733 | self.assertEqual('refs/heads/master', |
| 1734 | git_cl.GetTargetRef('origin', |
| 1735 | 'refs/remotes/branch-heads/123', |
Andrii Shyshkalov | f3a20ae | 2017-01-24 21:23:57 +0100 | [diff] [blame] | 1736 | branch)) |
wittman@chromium.org | 455dc92 | 2015-01-26 20:15:50 +0000 | [diff] [blame] | 1737 | |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 1738 | def test_patch_when_dirty(self): |
| 1739 | # Patch when local tree is dirty |
| 1740 | self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
| 1741 | self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
| 1742 | |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1743 | @staticmethod |
| 1744 | def _get_gerrit_codereview_server_calls(branch, value=None, |
| 1745 | git_short_host='host', |
Aaron Gable | 697a91b | 2018-01-19 15:20:15 -0800 | [diff] [blame] | 1746 | detect_branch=True, |
| 1747 | detect_server=True): |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1748 | """Returns calls executed by _GerritChangelistImpl.GetCodereviewServer. |
| 1749 | |
| 1750 | If value is given, branch.<BRANCH>.gerritcodereview is already set. |
| 1751 | """ |
| 1752 | calls = [] |
| 1753 | if detect_branch: |
| 1754 | calls.append(((['git', 'symbolic-ref', 'HEAD'],), branch)) |
Aaron Gable | 697a91b | 2018-01-19 15:20:15 -0800 | [diff] [blame] | 1755 | if detect_server: |
| 1756 | calls.append(((['git', 'config', 'branch.' + branch + '.gerritserver'],), |
| 1757 | CERR1 if value is None else value)) |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1758 | if value is None: |
| 1759 | calls += [ |
| 1760 | ((['git', 'config', 'branch.' + branch + '.merge'],), |
| 1761 | 'refs/heads' + branch), |
| 1762 | ((['git', 'config', 'branch.' + branch + '.remote'],), |
| 1763 | 'origin'), |
| 1764 | ((['git', 'config', 'remote.origin.url'],), |
| 1765 | 'https://%s.googlesource.com/my/repo' % git_short_host), |
| 1766 | ] |
| 1767 | return calls |
| 1768 | |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1769 | def _patch_common(self, force_codereview=False, |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1770 | new_branch=False, git_short_host='host', |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1771 | detect_gerrit_server=False, |
| 1772 | actual_codereview=None, |
| 1773 | codereview_in_url=False): |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 1774 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
tandrii@chromium.org | aa5ced1 | 2016-03-29 09:41:14 +0000 | [diff] [blame] | 1775 | self.mock(git_cl._RietveldChangelistImpl, 'GetMostRecentPatchset', |
| 1776 | lambda x: '60001') |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1777 | self.mock(git_cl._RietveldChangelistImpl, 'FetchDescription', |
Kenneth Russell | 61e2ed4 | 2017-02-15 11:47:13 -0800 | [diff] [blame] | 1778 | lambda *a, **kw: 'Description') |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 1779 | self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) |
| 1780 | |
tandrii | df09a46 | 2016-08-18 16:23:55 -0700 | [diff] [blame] | 1781 | if new_branch: |
| 1782 | self.calls = [((['git', 'new-branch', 'master'],), ''),] |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1783 | |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1784 | if codereview_in_url and actual_codereview == 'rietveld': |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1785 | self.calls += [ |
| 1786 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1787 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1788 | ] |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1789 | |
| 1790 | if not force_codereview and not codereview_in_url: |
| 1791 | # These calls detect codereview to use. |
| 1792 | self.calls += [ |
| 1793 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 1794 | ((['git', 'config', 'branch.master.rietveldissue'],), CERR1), |
| 1795 | ((['git', 'config', 'branch.master.gerritissue'],), CERR1), |
| 1796 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 1797 | ((['git', 'config', 'gerrit.host'],), 'true'), |
| 1798 | ] |
| 1799 | if detect_gerrit_server: |
| 1800 | self.calls += self._get_gerrit_codereview_server_calls( |
| 1801 | 'master', git_short_host=git_short_host, |
| 1802 | detect_branch=not new_branch and force_codereview) |
| 1803 | actual_codereview = 'gerrit' |
| 1804 | |
| 1805 | if actual_codereview == 'gerrit': |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1806 | self.calls += [ |
| 1807 | (('GetChangeDetail', git_short_host + '-review.googlesource.com', |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 1808 | 'my%2Frepo~123456', ['ALL_REVISIONS', 'CURRENT_COMMIT']), |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1809 | { |
| 1810 | 'current_revision': '7777777777', |
| 1811 | 'revisions': { |
| 1812 | '1111111111': { |
| 1813 | '_number': 1, |
| 1814 | 'fetch': {'http': { |
| 1815 | 'url': 'https://%s.googlesource.com/my/repo' % git_short_host, |
| 1816 | 'ref': 'refs/changes/56/123456/1', |
| 1817 | }}, |
| 1818 | }, |
| 1819 | '7777777777': { |
| 1820 | '_number': 7, |
| 1821 | 'fetch': {'http': { |
| 1822 | 'url': 'https://%s.googlesource.com/my/repo' % git_short_host, |
| 1823 | 'ref': 'refs/changes/56/123456/7', |
| 1824 | }}, |
| 1825 | }, |
| 1826 | }, |
| 1827 | }), |
| 1828 | ] |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 1829 | |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1830 | def test_patch_rietveld_guess_by_url(self): |
| 1831 | self._patch_common(actual_codereview='rietveld', codereview_in_url=True) |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 1832 | self.calls += [ |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1833 | ((['git', 'config', 'branch.master.rietveldissue', '123456'],), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1834 | ''), |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1835 | ((['git', 'config', 'branch.master.rietveldserver', |
| 1836 | 'https://codereview.example.com'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1837 | ((['git', 'config', 'branch.master.rietveldpatchset', '60001'],), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1838 | ''), |
Aaron Gable | d343c63 | 2017-03-15 11:02:26 -0700 | [diff] [blame] | 1839 | ((['git', 'commit', '-m', |
| 1840 | 'Description\n\n' + |
| 1841 | 'patch from issue 123456 at patchset 60001 ' + |
| 1842 | '(http://crrev.com/123456#ps60001)'],), ''), |
wychen@chromium.org | a872e75 | 2015-04-28 23:42:18 +0000 | [diff] [blame] | 1843 | ] |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1844 | self.assertEqual(git_cl.main( |
| 1845 | ['patch', 'https://codereview.example.com/123456']), 0) |
| 1846 | |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1847 | def test_patch_gerrit_default(self): |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1848 | self._patch_common(git_short_host='chromium', detect_gerrit_server=True) |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1849 | self.calls += [ |
| 1850 | ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', |
| 1851 | 'refs/changes/56/123456/7'],), ''), |
Aaron Gable | 62619a3 | 2017-06-16 08:22:09 -0700 | [diff] [blame] | 1852 | ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1853 | ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
Aaron Gable | 697a91b | 2018-01-19 15:20:15 -0800 | [diff] [blame] | 1854 | ''), |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1855 | ((['git', 'config', 'branch.master.gerritserver', |
| 1856 | 'https://chromium-review.googlesource.com'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1857 | ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''), |
Aaron Gable | 9387b4f | 2017-06-08 10:50:03 -0700 | [diff] [blame] | 1858 | ((['git', 'rev-parse', 'FETCH_HEAD'],), 'deadbeef'), |
| 1859 | ((['git', 'config', 'branch.master.last-upload-hash', 'deadbeef'],), ''), |
| 1860 | ((['git', 'config', 'branch.master.gerritsquashhash', 'deadbeef'],), ''), |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1861 | ] |
| 1862 | self.assertEqual(git_cl.main(['patch', '123456']), 0) |
| 1863 | |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1864 | def test_patch_gerrit_new_branch(self): |
| 1865 | self._patch_common( |
| 1866 | git_short_host='chromium', detect_gerrit_server=True, new_branch=True) |
| 1867 | self.calls += [ |
| 1868 | ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', |
| 1869 | 'refs/changes/56/123456/7'],), ''), |
| 1870 | ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), |
| 1871 | ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
| 1872 | ''), |
| 1873 | ((['git', 'config', 'branch.master.gerritserver', |
| 1874 | 'https://chromium-review.googlesource.com'],), ''), |
| 1875 | ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''), |
| 1876 | ((['git', 'rev-parse', 'FETCH_HEAD'],), 'deadbeef'), |
| 1877 | ((['git', 'config', 'branch.master.last-upload-hash', 'deadbeef'],), ''), |
| 1878 | ((['git', 'config', 'branch.master.gerritsquashhash', 'deadbeef'],), ''), |
| 1879 | ] |
| 1880 | self.assertEqual(git_cl.main(['patch', '-b', 'master', '123456']), 0) |
| 1881 | |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1882 | def test_patch_gerrit_force(self): |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1883 | self._patch_common( |
| 1884 | force_codereview=True, git_short_host='host', detect_gerrit_server=True) |
tandrii@chromium.org | dde6462 | 2016-04-13 17:11:21 +0000 | [diff] [blame] | 1885 | self.calls += [ |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1886 | ((['git', 'fetch', 'https://host.googlesource.com/my/repo', |
tandrii@chromium.org | dde6462 | 2016-04-13 17:11:21 +0000 | [diff] [blame] | 1887 | 'refs/changes/56/123456/7'],), ''), |
Aaron Gable | 9387b4f | 2017-06-08 10:50:03 -0700 | [diff] [blame] | 1888 | ((['git', 'reset', '--hard', 'FETCH_HEAD'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1889 | ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1890 | ''), |
tandrii@chromium.org | dde6462 | 2016-04-13 17:11:21 +0000 | [diff] [blame] | 1891 | ((['git', 'config', 'branch.master.gerritserver', |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1892 | 'https://host-review.googlesource.com'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1893 | ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''), |
Aaron Gable | 9387b4f | 2017-06-08 10:50:03 -0700 | [diff] [blame] | 1894 | ((['git', 'rev-parse', 'FETCH_HEAD'],), 'deadbeef'), |
| 1895 | ((['git', 'config', 'branch.master.last-upload-hash', 'deadbeef'],), ''), |
| 1896 | ((['git', 'config', 'branch.master.gerritsquashhash', 'deadbeef'],), ''), |
tandrii@chromium.org | dde6462 | 2016-04-13 17:11:21 +0000 | [diff] [blame] | 1897 | ] |
Aaron Gable | 62619a3 | 2017-06-16 08:22:09 -0700 | [diff] [blame] | 1898 | self.assertEqual(git_cl.main(['patch', '--gerrit', '123456', '--force']), 0) |
tandrii@chromium.org | dde6462 | 2016-04-13 17:11:21 +0000 | [diff] [blame] | 1899 | |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1900 | def test_patch_gerrit_guess_by_url(self): |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 1901 | self.calls += self._get_gerrit_codereview_server_calls( |
| 1902 | 'master', git_short_host='else', detect_server=False) |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1903 | self._patch_common( |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1904 | actual_codereview='gerrit', git_short_host='else', |
| 1905 | codereview_in_url=True, detect_gerrit_server=False) |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1906 | self.calls += [ |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1907 | ((['git', 'fetch', 'https://else.googlesource.com/my/repo', |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1908 | 'refs/changes/56/123456/1'],), ''), |
Aaron Gable | 62619a3 | 2017-06-16 08:22:09 -0700 | [diff] [blame] | 1909 | ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1910 | ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1911 | ''), |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1912 | ((['git', 'config', 'branch.master.gerritserver', |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1913 | 'https://else-review.googlesource.com'],), ''), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 1914 | ((['git', 'config', 'branch.master.gerritpatchset', '1'],), ''), |
Aaron Gable | 9387b4f | 2017-06-08 10:50:03 -0700 | [diff] [blame] | 1915 | ((['git', 'rev-parse', 'FETCH_HEAD'],), 'deadbeef'), |
| 1916 | ((['git', 'config', 'branch.master.last-upload-hash', 'deadbeef'],), ''), |
| 1917 | ((['git', 'config', 'branch.master.gerritsquashhash', 'deadbeef'],), ''), |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1918 | ] |
| 1919 | self.assertEqual(git_cl.main( |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 1920 | ['patch', 'https://else-review.googlesource.com/#/c/123456/1']), 0) |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1921 | |
Aaron Gable | 697a91b | 2018-01-19 15:20:15 -0800 | [diff] [blame] | 1922 | def test_patch_gerrit_guess_by_url_with_repo(self): |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 1923 | self.calls += self._get_gerrit_codereview_server_calls( |
| 1924 | 'master', git_short_host='else', detect_server=False) |
Aaron Gable | 697a91b | 2018-01-19 15:20:15 -0800 | [diff] [blame] | 1925 | self._patch_common( |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1926 | actual_codereview='gerrit', git_short_host='else', |
| 1927 | codereview_in_url=True, detect_gerrit_server=False) |
Aaron Gable | 697a91b | 2018-01-19 15:20:15 -0800 | [diff] [blame] | 1928 | self.calls += [ |
| 1929 | ((['git', 'fetch', 'https://else.googlesource.com/my/repo', |
| 1930 | 'refs/changes/56/123456/1'],), ''), |
| 1931 | ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), |
| 1932 | ((['git', 'config', 'branch.master.gerritissue', '123456'],), |
| 1933 | ''), |
| 1934 | ((['git', 'config', 'branch.master.gerritserver', |
| 1935 | 'https://else-review.googlesource.com'],), ''), |
| 1936 | ((['git', 'config', 'branch.master.gerritpatchset', '1'],), ''), |
| 1937 | ((['git', 'rev-parse', 'FETCH_HEAD'],), 'deadbeef'), |
| 1938 | ((['git', 'config', 'branch.master.last-upload-hash', 'deadbeef'],), ''), |
| 1939 | ((['git', 'config', 'branch.master.gerritsquashhash', 'deadbeef'],), ''), |
| 1940 | ] |
| 1941 | self.assertEqual(git_cl.main( |
| 1942 | ['patch', 'https://else-review.googlesource.com/c/my/repo/+/123456/1']), |
| 1943 | 0) |
| 1944 | |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1945 | def test_patch_gerrit_conflict(self): |
Andrii Shyshkalov | f57841b | 2018-08-28 00:48:53 +0000 | [diff] [blame] | 1946 | self._patch_common(detect_gerrit_server=True, git_short_host='chromium') |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1947 | self.calls += [ |
| 1948 | ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1949 | 'refs/changes/56/123456/7'],), ''), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 1950 | ((['git', 'cherry-pick', 'FETCH_HEAD'],), CERR1), |
| 1951 | ((['DieWithError', 'Command "git cherry-pick FETCH_HEAD" failed.\n'],), |
| 1952 | SystemExitMock()), |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1953 | ] |
| 1954 | with self.assertRaises(SystemExitMock): |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1955 | git_cl.main(['patch', '123456']) |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 1956 | |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1957 | def test_patch_gerrit_not_exists(self): |
Andrii Shyshkalov | c6c8b4c | 2016-11-09 20:51:20 +0100 | [diff] [blame] | 1958 | def notExists(_issue, *_, **kwargs): |
Andrii Shyshkalov | c6c8b4c | 2016-11-09 20:51:20 +0100 | [diff] [blame] | 1959 | raise git_cl.gerrit_util.GerritError(404, '') |
| 1960 | self.mock(git_cl.gerrit_util, 'GetChangeDetail', notExists) |
| 1961 | |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 1962 | self.calls = [ |
| 1963 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 1964 | ((['git', 'config', 'branch.master.rietveldissue'],), CERR1), |
| 1965 | ((['git', 'config', 'branch.master.gerritissue'],), CERR1), |
| 1966 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 1967 | ((['git', 'config', 'gerrit.host'],), 'true'), |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1968 | ((['git', 'config', 'branch.master.gerritserver'],), CERR1), |
| 1969 | ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'), |
| 1970 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 1971 | ((['git', 'config', 'remote.origin.url'],), |
| 1972 | 'https://chromium.googlesource.com/my/repo'), |
| 1973 | ((['DieWithError', |
| 1974 | 'change 123456 at https://chromium-review.googlesource.com does not ' |
| 1975 | 'exist or you have no access to it'],), SystemExitMock()), |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 1976 | ] |
| 1977 | with self.assertRaises(SystemExitMock): |
Andrii Shyshkalov | c971239 | 2017-04-11 13:35:21 +0200 | [diff] [blame] | 1978 | self.assertEqual(1, git_cl.main(['patch', '123456'])) |
tandrii | c2405f5 | 2016-10-10 08:13:15 -0700 | [diff] [blame] | 1979 | |
tandrii@chromium.org | 5df290f | 2016-04-11 16:12:29 +0000 | [diff] [blame] | 1980 | def _checkout_calls(self): |
| 1981 | return [ |
| 1982 | ((['git', 'config', '--local', '--get-regexp', |
| 1983 | 'branch\\..*\\.rietveldissue'], ), |
| 1984 | ('branch.retrying.rietveldissue 1111111111\n' |
| 1985 | 'branch.some-fix.rietveldissue 2222222222\n')), |
| 1986 | ((['git', 'config', '--local', '--get-regexp', |
| 1987 | 'branch\\..*\\.gerritissue'], ), |
| 1988 | ('branch.ger-branch.gerritissue 123456\n' |
| 1989 | 'branch.gbranch654.gerritissue 654321\n')), |
| 1990 | ] |
| 1991 | |
| 1992 | def test_checkout_gerrit(self): |
| 1993 | """Tests git cl checkout <issue>.""" |
| 1994 | self.calls = self._checkout_calls() |
| 1995 | self.calls += [((['git', 'checkout', 'ger-branch'], ), '')] |
| 1996 | self.assertEqual(0, git_cl.main(['checkout', '123456'])) |
| 1997 | |
| 1998 | def test_checkout_rietveld(self): |
| 1999 | """Tests git cl checkout <issue>.""" |
| 2000 | self.calls = self._checkout_calls() |
| 2001 | self.calls += [((['git', 'checkout', 'some-fix'], ), '')] |
| 2002 | self.assertEqual(0, git_cl.main(['checkout', '2222222222'])) |
| 2003 | |
| 2004 | def test_checkout_not_found(self): |
| 2005 | """Tests git cl checkout <issue>.""" |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2006 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
tandrii@chromium.org | 5df290f | 2016-04-11 16:12:29 +0000 | [diff] [blame] | 2007 | self.calls = self._checkout_calls() |
| 2008 | self.assertEqual(1, git_cl.main(['checkout', '99999'])) |
| 2009 | |
tandrii@chromium.org | 26c8fd2 | 2016-04-11 21:33:21 +0000 | [diff] [blame] | 2010 | def test_checkout_no_branch_issues(self): |
| 2011 | """Tests git cl checkout <issue>.""" |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2012 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
tandrii@chromium.org | 26c8fd2 | 2016-04-11 21:33:21 +0000 | [diff] [blame] | 2013 | self.calls = [ |
| 2014 | ((['git', 'config', '--local', '--get-regexp', |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 2015 | 'branch\\..*\\.rietveldissue'], ), CERR1), |
tandrii@chromium.org | 26c8fd2 | 2016-04-11 21:33:21 +0000 | [diff] [blame] | 2016 | ((['git', 'config', '--local', '--get-regexp', |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 2017 | 'branch\\..*\\.gerritissue'], ), CERR1), |
tandrii@chromium.org | 26c8fd2 | 2016-04-11 21:33:21 +0000 | [diff] [blame] | 2018 | ] |
| 2019 | self.assertEqual(1, git_cl.main(['checkout', '99999'])) |
| 2020 | |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2021 | def _test_gerrit_ensure_authenticated_common(self, auth, |
| 2022 | skip_auth_check=False): |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2023 | self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', |
| 2024 | CookiesAuthenticatorMockFactory(hosts_with_creds=auth)) |
| 2025 | self.mock(git_cl, 'DieWithError', |
Christopher Lam | f732cd5 | 2017-01-24 12:40:11 +1100 | [diff] [blame] | 2026 | lambda msg, change=None: self._mocked_call(['DieWithError', msg])) |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2027 | self.calls = self._gerrit_ensure_auth_calls(skip_auth_check=skip_auth_check) |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2028 | cl = git_cl.Changelist(codereview='gerrit') |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2029 | cl.branch = 'master' |
| 2030 | cl.branchref = 'refs/heads/master' |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2031 | cl.lookedup_issue = True |
| 2032 | return cl |
| 2033 | |
| 2034 | def test_gerrit_ensure_authenticated_missing(self): |
| 2035 | cl = self._test_gerrit_ensure_authenticated_common(auth={ |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 2036 | 'chromium.googlesource.com': ('git-is.ok', '', 'but gerrit is missing'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2037 | }) |
| 2038 | self.calls.append( |
| 2039 | ((['DieWithError', |
| 2040 | 'Credentials for the following hosts are required:\n' |
| 2041 | ' chromium-review.googlesource.com\n' |
| 2042 | 'These are read from ~/.gitcookies (or legacy ~/.netrc)\n' |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 2043 | 'You can (re)generate your credentials by visiting ' |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2044 | 'https://chromium-review.googlesource.com/new-password'],), ''),) |
| 2045 | self.assertIsNone(cl.EnsureAuthenticated(force=False)) |
| 2046 | |
| 2047 | def test_gerrit_ensure_authenticated_conflict(self): |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2048 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2049 | cl = self._test_gerrit_ensure_authenticated_common(auth={ |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 2050 | 'chromium.googlesource.com': |
| 2051 | ('git-one.example.com', None, 'secret1'), |
| 2052 | 'chromium-review.googlesource.com': |
| 2053 | ('git-other.example.com', None, 'secret2'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2054 | }) |
| 2055 | self.calls.append( |
Andrii Shyshkalov | abc26ac | 2017-03-14 14:49:38 +0100 | [diff] [blame] | 2056 | (('ask_for_data', 'If you know what you are doing ' |
| 2057 | 'press Enter to continue, or Ctrl+C to abort'), '')) |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2058 | self.assertIsNone(cl.EnsureAuthenticated(force=False)) |
| 2059 | |
| 2060 | def test_gerrit_ensure_authenticated_ok(self): |
| 2061 | cl = self._test_gerrit_ensure_authenticated_common(auth={ |
Andrii Shyshkalov | bb86fbb | 2017-03-24 14:59:28 +0100 | [diff] [blame] | 2062 | 'chromium.googlesource.com': |
| 2063 | ('git-same.example.com', None, 'secret'), |
| 2064 | 'chromium-review.googlesource.com': |
| 2065 | ('git-same.example.com', None, 'secret'), |
tandrii@chromium.org | fe30f18 | 2016-04-13 12:15:04 +0000 | [diff] [blame] | 2066 | }) |
| 2067 | self.assertIsNone(cl.EnsureAuthenticated(force=False)) |
| 2068 | |
tandrii@chromium.org | 2825353 | 2016-04-14 13:46:56 +0000 | [diff] [blame] | 2069 | def test_gerrit_ensure_authenticated_skipped(self): |
| 2070 | cl = self._test_gerrit_ensure_authenticated_common( |
| 2071 | auth={}, skip_auth_check=True) |
| 2072 | self.assertIsNone(cl.EnsureAuthenticated(force=False)) |
| 2073 | |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2074 | def test_cmd_set_commit_rietveld(self): |
tandrii | 4d84359 | 2016-07-27 08:22:56 -0700 | [diff] [blame] | 2075 | self.mock(git_cl._RietveldChangelistImpl, 'SetFlags', |
| 2076 | lambda _, v: self._mocked_call(['SetFlags', v])) |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2077 | self.calls = [ |
| 2078 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2079 | ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2080 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 2081 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2082 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2083 | ((['git', 'config', 'branch.feature.rietveldserver'],), |
| 2084 | 'https://codereview.chromium.org'), |
tandrii | 4d84359 | 2016-07-27 08:22:56 -0700 | [diff] [blame] | 2085 | ((['SetFlags', {'commit': '1', 'cq_dry_run': '0'}], ), ''), |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2086 | ] |
| 2087 | self.assertEqual(0, git_cl.main(['set-commit'])) |
| 2088 | |
Andrii Shyshkalov | 828701b | 2016-12-09 10:46:47 +0100 | [diff] [blame] | 2089 | def _cmd_set_commit_gerrit_common(self, vote, notify=None): |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2090 | self.mock(git_cl.gerrit_util, 'SetReview', |
Andrii Shyshkalov | 828701b | 2016-12-09 10:46:47 +0100 | [diff] [blame] | 2091 | lambda h, i, labels, notify=None: |
| 2092 | self._mocked_call(['SetReview', h, i, labels, notify])) |
| 2093 | |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2094 | self.calls = [ |
| 2095 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2096 | ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 2097 | ((['git', 'config', 'branch.feature.gerritissue'],), '123'), |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2098 | ((['git', 'config', 'branch.feature.gerritserver'],), |
| 2099 | 'https://chromium-review.googlesource.com'), |
Andrii Shyshkalov | 889677c | 2018-08-28 20:43:06 +0000 | [diff] [blame] | 2100 | ((['git', 'config', 'branch.feature.merge'],), 'refs/heads/master'), |
| 2101 | ((['git', 'config', 'branch.feature.remote'],), 'origin'), |
| 2102 | ((['git', 'config', 'remote.origin.url'],), |
| 2103 | 'https://chromium.googlesource.com/infra/infra.git'), |
| 2104 | ((['SetReview', 'chromium-review.googlesource.com', |
| 2105 | 'infra%2Finfra~123', |
Andrii Shyshkalov | 828701b | 2016-12-09 10:46:47 +0100 | [diff] [blame] | 2106 | {'Commit-Queue': vote}, notify],), ''), |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2107 | ] |
tandrii | d9e5ce5 | 2016-07-13 02:32:59 -0700 | [diff] [blame] | 2108 | |
| 2109 | def test_cmd_set_commit_gerrit_clear(self): |
| 2110 | self._cmd_set_commit_gerrit_common(0) |
| 2111 | self.assertEqual(0, git_cl.main(['set-commit', '-c'])) |
| 2112 | |
| 2113 | def test_cmd_set_commit_gerrit_dry(self): |
Aaron Gable | 75e7872 | 2017-06-09 10:40:16 -0700 | [diff] [blame] | 2114 | self._cmd_set_commit_gerrit_common(1, notify=False) |
tandrii@chromium.org | fa330e8 | 2016-04-13 17:09:52 +0000 | [diff] [blame] | 2115 | self.assertEqual(0, git_cl.main(['set-commit', '-d'])) |
| 2116 | |
tandrii | d9e5ce5 | 2016-07-13 02:32:59 -0700 | [diff] [blame] | 2117 | def test_cmd_set_commit_gerrit(self): |
| 2118 | self._cmd_set_commit_gerrit_common(2) |
| 2119 | self.assertEqual(0, git_cl.main(['set-commit'])) |
| 2120 | |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2121 | def test_description_display(self): |
| 2122 | out = StringIO.StringIO() |
| 2123 | self.mock(git_cl.sys, 'stdout', out) |
| 2124 | |
martiniss@chromium.org | d6648e2 | 2016-04-29 19:22:16 +0000 | [diff] [blame] | 2125 | self.mock(git_cl, 'Changelist', ChangelistMock) |
| 2126 | ChangelistMock.desc = 'foo\n' |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2127 | |
| 2128 | self.assertEqual(0, git_cl.main(['description', '-d'])) |
| 2129 | self.assertEqual('foo\n', out.getvalue()) |
| 2130 | |
| 2131 | def test_description_rietveld(self): |
| 2132 | out = StringIO.StringIO() |
| 2133 | self.mock(git_cl.sys, 'stdout', out) |
martiniss | 6eda05f | 2016-06-30 10:18:35 -0700 | [diff] [blame] | 2134 | self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'foobar') |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2135 | |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2136 | self.assertEqual(0, git_cl.main([ |
Andrii Shyshkalov | 28d840e | 2017-04-10 15:45:09 +0200 | [diff] [blame] | 2137 | 'description', '-d', '--rietveld', 'https://code.review.org/123123'])) |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2138 | self.assertEqual('foobar\n', out.getvalue()) |
| 2139 | |
iannucci | 3c972b9 | 2016-08-17 13:24:10 -0700 | [diff] [blame] | 2140 | def test_StatusFieldOverrideIssueMissingArgs(self): |
| 2141 | out = StringIO.StringIO() |
| 2142 | self.mock(git_cl.sys, 'stderr', out) |
| 2143 | |
| 2144 | try: |
| 2145 | self.assertEqual(git_cl.main(['status', '--issue', '1']), 0) |
| 2146 | except SystemExit as ex: |
| 2147 | self.assertEqual(ex.code, 2) |
iannucci | e53c935 | 2016-08-17 14:40:40 -0700 | [diff] [blame] | 2148 | self.assertRegexpMatches(out.getvalue(), r'--issue must be specified') |
iannucci | 3c972b9 | 2016-08-17 13:24:10 -0700 | [diff] [blame] | 2149 | |
| 2150 | out = StringIO.StringIO() |
| 2151 | self.mock(git_cl.sys, 'stderr', out) |
| 2152 | |
| 2153 | try: |
| 2154 | self.assertEqual(git_cl.main(['status', '--issue', '1', '--rietveld']), 0) |
| 2155 | except SystemExit as ex: |
| 2156 | self.assertEqual(ex.code, 2) |
iannucci | e53c935 | 2016-08-17 14:40:40 -0700 | [diff] [blame] | 2157 | self.assertRegexpMatches(out.getvalue(), r'--field must be specified') |
iannucci | 3c972b9 | 2016-08-17 13:24:10 -0700 | [diff] [blame] | 2158 | |
| 2159 | def test_StatusFieldOverrideIssue(self): |
| 2160 | out = StringIO.StringIO() |
| 2161 | self.mock(git_cl.sys, 'stdout', out) |
| 2162 | |
| 2163 | def assertIssue(cl_self, *_args): |
| 2164 | self.assertEquals(cl_self.issue, 1) |
| 2165 | return 'foobar' |
| 2166 | |
| 2167 | self.mock(git_cl.Changelist, 'GetDescription', assertIssue) |
| 2168 | self.calls = [ |
| 2169 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 2170 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2171 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2172 | ] |
iannucci | e53c935 | 2016-08-17 14:40:40 -0700 | [diff] [blame] | 2173 | self.assertEqual( |
| 2174 | git_cl.main(['status', '--issue', '1', '--rietveld', '--field', 'desc']), |
| 2175 | 0) |
iannucci | 3c972b9 | 2016-08-17 13:24:10 -0700 | [diff] [blame] | 2176 | self.assertEqual(out.getvalue(), 'foobar\n') |
| 2177 | |
iannucci | e53c935 | 2016-08-17 14:40:40 -0700 | [diff] [blame] | 2178 | def test_SetCloseOverrideIssue(self): |
| 2179 | def assertIssue(cl_self, *_args): |
| 2180 | self.assertEquals(cl_self.issue, 1) |
| 2181 | return 'foobar' |
| 2182 | |
| 2183 | self.mock(git_cl.Changelist, 'GetDescription', assertIssue) |
| 2184 | self.mock(git_cl.Changelist, 'CloseIssue', lambda *_: None) |
| 2185 | self.calls = [ |
| 2186 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 2187 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2188 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2189 | ] |
| 2190 | self.assertEqual( |
| 2191 | git_cl.main(['set-close', '--issue', '1', '--rietveld']), 0) |
| 2192 | |
| 2193 | def test_SetCommitOverrideIssue(self): |
| 2194 | def assertIssue(cl_self, *_args): |
| 2195 | self.assertEquals(cl_self.issue, 1) |
| 2196 | return 'foobar' |
| 2197 | |
| 2198 | self.mock(git_cl.Changelist, 'GetDescription', assertIssue) |
| 2199 | self.mock(git_cl.Changelist, 'SetCQState', lambda *_: None) |
| 2200 | self.calls = [ |
| 2201 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 2202 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2203 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2204 | ((['git', 'symbolic-ref', 'HEAD'],), ''), |
| 2205 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2206 | ((['git', 'config', 'rietveld.server'],), ''), |
| 2207 | ] |
| 2208 | self.assertEqual( |
| 2209 | git_cl.main(['set-close', '--issue', '1', '--rietveld']), 0) |
| 2210 | |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2211 | def test_description_gerrit(self): |
| 2212 | out = StringIO.StringIO() |
| 2213 | self.mock(git_cl.sys, 'stdout', out) |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 2214 | self.calls = [ |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 2215 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2216 | ((['git', 'config', 'branch.feature.merge'],), 'feature'), |
| 2217 | ((['git', 'config', 'branch.feature.remote'],), 'origin'), |
| 2218 | ((['git', 'config', 'remote.origin.url'],), |
| 2219 | 'https://chromium.googlesource.com/my/repo'), |
Andrii Shyshkalov | 8039be7 | 2017-01-26 09:38:18 +0100 | [diff] [blame] | 2220 | (('GetChangeDetail', 'code.review.org', |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 2221 | 'my%2Frepo~123123', ['CURRENT_REVISION', 'CURRENT_COMMIT']), |
Andrii Shyshkalov | 8fc0c1d | 2017-01-26 09:38:10 +0100 | [diff] [blame] | 2222 | { |
| 2223 | 'current_revision': 'sha1', |
| 2224 | 'revisions': {'sha1': { |
| 2225 | 'commit': {'message': 'foobar'}, |
| 2226 | }}, |
| 2227 | }), |
| 2228 | ] |
martiniss@chromium.org | 2b55fe3 | 2016-04-26 20:28:54 +0000 | [diff] [blame] | 2229 | self.assertEqual(0, git_cl.main([ |
| 2230 | 'description', 'https://code.review.org/123123', '-d', '--gerrit'])) |
| 2231 | self.assertEqual('foobar\n', out.getvalue()) |
| 2232 | |
martiniss@chromium.org | d6648e2 | 2016-04-29 19:22:16 +0000 | [diff] [blame] | 2233 | def test_description_set_raw(self): |
| 2234 | out = StringIO.StringIO() |
| 2235 | self.mock(git_cl.sys, 'stdout', out) |
| 2236 | |
| 2237 | self.mock(git_cl, 'Changelist', ChangelistMock) |
| 2238 | self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hihi')) |
| 2239 | |
| 2240 | self.assertEqual(0, git_cl.main(['description', '-n', 'hihi'])) |
| 2241 | self.assertEqual('hihi', ChangelistMock.desc) |
| 2242 | |
tandrii@chromium.org | d605a51 | 2016-06-03 09:55:00 +0000 | [diff] [blame] | 2243 | def test_description_appends_bug_line(self): |
tandrii@chromium.org | 601e1d1 | 2016-06-03 13:03:54 +0000 | [diff] [blame] | 2244 | current_desc = 'Some.\n\nChange-Id: xxx' |
tandrii@chromium.org | d605a51 | 2016-06-03 09:55:00 +0000 | [diff] [blame] | 2245 | |
| 2246 | def RunEditor(desc, _, **kwargs): |
| 2247 | self.assertEquals( |
| 2248 | '# Enter a description of the change.\n' |
| 2249 | '# This will be displayed on the codereview site.\n' |
| 2250 | '# The first line will also be used as the subject of the review.\n' |
| 2251 | '#--------------------This line is 72 characters long' |
tandrii@chromium.org | 601e1d1 | 2016-06-03 13:03:54 +0000 | [diff] [blame] | 2252 | '--------------------\n' |
Aaron Gable | 3a16ed1 | 2017-03-23 10:51:55 -0700 | [diff] [blame] | 2253 | 'Some.\n\nChange-Id: xxx\nBug: ', |
tandrii@chromium.org | d605a51 | 2016-06-03 09:55:00 +0000 | [diff] [blame] | 2254 | desc) |
tandrii@chromium.org | 601e1d1 | 2016-06-03 13:03:54 +0000 | [diff] [blame] | 2255 | # Simulate user changing something. |
Aaron Gable | 3a16ed1 | 2017-03-23 10:51:55 -0700 | [diff] [blame] | 2256 | return 'Some.\n\nChange-Id: xxx\nBug: 123' |
tandrii@chromium.org | d605a51 | 2016-06-03 09:55:00 +0000 | [diff] [blame] | 2257 | |
dsansome | e2d6fd9 | 2016-09-08 00:10:47 -0700 | [diff] [blame] | 2258 | def UpdateDescriptionRemote(_, desc, force=False): |
Aaron Gable | 3a16ed1 | 2017-03-23 10:51:55 -0700 | [diff] [blame] | 2259 | self.assertEquals(desc, 'Some.\n\nChange-Id: xxx\nBug: 123') |
tandrii@chromium.org | d605a51 | 2016-06-03 09:55:00 +0000 | [diff] [blame] | 2260 | |
| 2261 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2262 | self.mock(git_cl.Changelist, 'GetDescription', |
| 2263 | lambda *args: current_desc) |
| 2264 | self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote', |
| 2265 | UpdateDescriptionRemote) |
| 2266 | self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
| 2267 | |
| 2268 | self.calls = [ |
| 2269 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2270 | ((['git', 'config', 'branch.feature.gerritissue'],), '123'), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 2271 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2272 | ((['git', 'config', 'rietveld.bug-prefix'],), CERR1), |
tandrii@chromium.org | d605a51 | 2016-06-03 09:55:00 +0000 | [diff] [blame] | 2273 | ((['git', 'config', 'core.editor'],), 'vi'), |
| 2274 | ] |
| 2275 | self.assertEqual(0, git_cl.main(['description', '--gerrit'])) |
| 2276 | |
martiniss@chromium.org | d6648e2 | 2016-04-29 19:22:16 +0000 | [diff] [blame] | 2277 | def test_description_set_stdin(self): |
| 2278 | out = StringIO.StringIO() |
| 2279 | self.mock(git_cl.sys, 'stdout', out) |
| 2280 | |
| 2281 | self.mock(git_cl, 'Changelist', ChangelistMock) |
| 2282 | self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) |
| 2283 | |
| 2284 | self.assertEqual(0, git_cl.main(['description', '-n', '-'])) |
| 2285 | self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) |
| 2286 | |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2287 | def test_archive(self): |
tandrii | 1c67da6 | 2016-06-10 07:35:53 -0700 | [diff] [blame] | 2288 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2289 | |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2290 | self.calls = \ |
| 2291 | [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), |
| 2292 | 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2293 | ((['git', 'config', 'branch.master.rietveldissue'],), '1'), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 2294 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2295 | ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2296 | ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), |
| 2297 | ((['git', 'config', 'branch.bar.rietveldissue'],), CERR1), |
| 2298 | ((['git', 'config', 'branch.bar.gerritissue'],), '789'), |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2299 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 2300 | ((['git', 'tag', 'git-cl-archived-456-foo', 'foo'],), ''), |
| 2301 | ((['git', 'branch', '-D', 'foo'],), '')] |
| 2302 | |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2303 | self.mock(git_cl, 'get_cl_statuses', |
| 2304 | lambda branches, fine_grained, max_processes: |
kmarshall | 9249e01 | 2016-08-23 12:02:16 -0700 | [diff] [blame] | 2305 | [(MockChangelistWithBranchAndIssue('master', 1), 'open'), |
| 2306 | (MockChangelistWithBranchAndIssue('foo', 456), 'closed'), |
| 2307 | (MockChangelistWithBranchAndIssue('bar', 789), 'open')]) |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2308 | |
| 2309 | self.assertEqual(0, git_cl.main(['archive', '-f'])) |
| 2310 | |
| 2311 | def test_archive_current_branch_fails(self): |
tandrii | 1c67da6 | 2016-06-10 07:35:53 -0700 | [diff] [blame] | 2312 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2313 | self.calls = \ |
| 2314 | [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), |
| 2315 | 'refs/heads/master'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2316 | ((['git', 'config', 'branch.master.rietveldissue'],), '1'), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 2317 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2318 | ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2319 | ((['git', 'symbolic-ref', 'HEAD'],), 'master')] |
| 2320 | |
kmarshall | 9249e01 | 2016-08-23 12:02:16 -0700 | [diff] [blame] | 2321 | self.mock(git_cl, 'get_cl_statuses', |
| 2322 | lambda branches, fine_grained, max_processes: |
| 2323 | [(MockChangelistWithBranchAndIssue('master', 1), 'closed')]) |
| 2324 | |
| 2325 | self.assertEqual(1, git_cl.main(['archive', '-f'])) |
| 2326 | |
| 2327 | def test_archive_dry_run(self): |
| 2328 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2329 | |
| 2330 | self.calls = \ |
| 2331 | [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), |
| 2332 | 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), |
| 2333 | ((['git', 'config', 'branch.master.rietveldissue'],), '1'), |
| 2334 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2335 | ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 2336 | ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), |
| 2337 | ((['git', 'config', 'branch.bar.rietveldissue'],), CERR1), |
| 2338 | ((['git', 'config', 'branch.bar.gerritissue'],), '789'), |
| 2339 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'),] |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2340 | |
| 2341 | self.mock(git_cl, 'get_cl_statuses', |
| 2342 | lambda branches, fine_grained, max_processes: |
kmarshall | 9249e01 | 2016-08-23 12:02:16 -0700 | [diff] [blame] | 2343 | [(MockChangelistWithBranchAndIssue('master', 1), 'open'), |
| 2344 | (MockChangelistWithBranchAndIssue('foo', 456), 'closed'), |
| 2345 | (MockChangelistWithBranchAndIssue('bar', 789), 'open')]) |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2346 | |
kmarshall | 9249e01 | 2016-08-23 12:02:16 -0700 | [diff] [blame] | 2347 | self.assertEqual(0, git_cl.main(['archive', '-f', '--dry-run'])) |
| 2348 | |
| 2349 | def test_archive_no_tags(self): |
| 2350 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2351 | |
| 2352 | self.calls = \ |
| 2353 | [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), |
| 2354 | 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), |
| 2355 | ((['git', 'config', 'branch.master.rietveldissue'],), '1'), |
| 2356 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2357 | ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 2358 | ((['git', 'config', 'branch.foo.rietveldissue'],), '456'), |
| 2359 | ((['git', 'config', 'branch.bar.rietveldissue'],), CERR1), |
| 2360 | ((['git', 'config', 'branch.bar.gerritissue'],), '789'), |
| 2361 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 2362 | ((['git', 'branch', '-D', 'foo'],), '')] |
| 2363 | |
| 2364 | self.mock(git_cl, 'get_cl_statuses', |
| 2365 | lambda branches, fine_grained, max_processes: |
| 2366 | [(MockChangelistWithBranchAndIssue('master', 1), 'open'), |
| 2367 | (MockChangelistWithBranchAndIssue('foo', 456), 'closed'), |
| 2368 | (MockChangelistWithBranchAndIssue('bar', 789), 'open')]) |
| 2369 | |
| 2370 | self.assertEqual(0, git_cl.main(['archive', '-f', '--notags'])) |
kmarshall | 3bff56b | 2016-06-06 18:31:47 -0700 | [diff] [blame] | 2371 | |
tandrii@chromium.org | 9b7fd71 | 2016-06-01 13:45:20 +0000 | [diff] [blame] | 2372 | def test_cmd_issue_erase_existing(self): |
| 2373 | out = StringIO.StringIO() |
| 2374 | self.mock(git_cl.sys, 'stdout', out) |
| 2375 | self.calls = [ |
| 2376 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2377 | ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 2378 | ((['git', 'config', 'branch.feature.gerritissue'],), '123'), |
tandrii@chromium.org | 9b7fd71 | 2016-06-01 13:45:20 +0000 | [diff] [blame] | 2379 | # Let this command raise exception (retcode=1) - it should be ignored. |
| 2380 | ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), |
tandrii | 5d48c32 | 2016-08-18 16:19:37 -0700 | [diff] [blame] | 2381 | CERR1), |
| 2382 | ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''), |
| 2383 | ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''), |
tandrii@chromium.org | 9b7fd71 | 2016-06-01 13:45:20 +0000 | [diff] [blame] | 2384 | ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''), |
| 2385 | ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), |
| 2386 | ''), |
Aaron Gable | ca01e2c | 2017-07-19 11:16:02 -0700 | [diff] [blame] | 2387 | ((['git', 'log', '-1', '--format=%B'],), 'This is a description'), |
tandrii@chromium.org | 9b7fd71 | 2016-06-01 13:45:20 +0000 | [diff] [blame] | 2388 | ] |
| 2389 | self.assertEqual(0, git_cl.main(['issue', '0'])) |
| 2390 | |
Aaron Gable | 400e989 | 2017-07-12 15:31:21 -0700 | [diff] [blame] | 2391 | def test_cmd_issue_erase_existing_with_change_id(self): |
| 2392 | out = StringIO.StringIO() |
| 2393 | self.mock(git_cl.sys, 'stdout', out) |
| 2394 | self.mock(git_cl.Changelist, 'GetDescription', |
| 2395 | lambda _: 'This is a description\n\nChange-Id: Ideadbeef') |
| 2396 | self.calls = [ |
| 2397 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2398 | ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 2399 | ((['git', 'config', 'branch.feature.gerritissue'],), '123'), |
Aaron Gable | 400e989 | 2017-07-12 15:31:21 -0700 | [diff] [blame] | 2400 | # Let this command raise exception (retcode=1) - it should be ignored. |
| 2401 | ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), |
| 2402 | CERR1), |
| 2403 | ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''), |
| 2404 | ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''), |
| 2405 | ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''), |
| 2406 | ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), |
| 2407 | ''), |
Aaron Gable | ca01e2c | 2017-07-19 11:16:02 -0700 | [diff] [blame] | 2408 | ((['git', 'log', '-1', '--format=%B'],), |
| 2409 | 'This is a description\n\nChange-Id: Ideadbeef'), |
| 2410 | ((['git', 'commit', '--amend', '-m', 'This is a description\n'],), ''), |
Aaron Gable | 400e989 | 2017-07-12 15:31:21 -0700 | [diff] [blame] | 2411 | ] |
| 2412 | self.assertEqual(0, git_cl.main(['issue', '0'])) |
| 2413 | |
phajdan.jr | e328cf9 | 2016-08-22 04:12:17 -0700 | [diff] [blame] | 2414 | def test_cmd_issue_json(self): |
| 2415 | out = StringIO.StringIO() |
| 2416 | self.mock(git_cl.sys, 'stdout', out) |
| 2417 | self.calls = [ |
| 2418 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2419 | ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
phajdan.jr | e328cf9 | 2016-08-22 04:12:17 -0700 | [diff] [blame] | 2420 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 2421 | ((['git', 'config', 'rietveld.server'],), |
| 2422 | 'https://codereview.chromium.org'), |
| 2423 | ((['git', 'config', 'branch.feature.rietveldserver'],), ''), |
| 2424 | (('write_json', 'output.json', |
| 2425 | {'issue': 123, 'issue_url': 'https://codereview.chromium.org/123'}), |
| 2426 | ''), |
| 2427 | ] |
| 2428 | self.assertEqual(0, git_cl.main(['issue', '--json', 'output.json'])) |
| 2429 | |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2430 | def test_git_cl_try_default_cq_dry_run(self): |
tandrii | 9de9ec6 | 2016-07-13 03:01:59 -0700 | [diff] [blame] | 2431 | self.mock(git_cl.Changelist, 'GetChange', |
| 2432 | lambda _, *a: ( |
| 2433 | self._mocked_call(['GetChange']+list(a)))) |
| 2434 | self.mock(git_cl.presubmit_support, 'DoGetTryMasters', |
| 2435 | lambda *_, **__: ( |
| 2436 | self._mocked_call(['DoGetTryMasters']))) |
tandrii | 9de9ec6 | 2016-07-13 03:01:59 -0700 | [diff] [blame] | 2437 | self.mock(git_cl._RietveldChangelistImpl, 'SetCQState', |
| 2438 | lambda _, s: self._mocked_call(['SetCQState', s])) |
| 2439 | self.calls = [ |
| 2440 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
tandrii | 33a46ff | 2016-08-23 05:53:40 -0700 | [diff] [blame] | 2441 | ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
tandrii | 9de9ec6 | 2016-07-13 03:01:59 -0700 | [diff] [blame] | 2442 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 2443 | ((['git', 'config', 'rietveld.server'],), |
| 2444 | 'https://codereview.chromium.org'), |
| 2445 | ((['git', 'config', 'branch.feature.rietveldserver'],), ''), |
| 2446 | ((['git', 'config', 'branch.feature.merge'],), 'feature'), |
| 2447 | ((['git', 'config', 'branch.feature.remote'],), 'origin'), |
| 2448 | ((['get_or_create_merge_base', 'feature', 'feature'],), |
| 2449 | 'fake_ancestor_sha'), |
| 2450 | ((['GetChange', 'fake_ancestor_sha', None], ), |
| 2451 | git_cl.presubmit_support.GitChange( |
| 2452 | '', '', '', '', '', '', '', '')), |
| 2453 | ((['git', 'rev-parse', '--show-cdup'],), '../'), |
| 2454 | ((['DoGetTryMasters'], ), None), |
tandrii | 9de9ec6 | 2016-07-13 03:01:59 -0700 | [diff] [blame] | 2455 | ((['SetCQState', git_cl._CQState.DRY_RUN], ), None), |
| 2456 | ] |
| 2457 | out = StringIO.StringIO() |
| 2458 | self.mock(git_cl.sys, 'stdout', out) |
| 2459 | self.assertEqual(0, git_cl.main(['try'])) |
| 2460 | self.assertEqual( |
| 2461 | out.getvalue(), |
Quinten Yearsley | fc5fd92 | 2017-05-31 11:50:52 -0700 | [diff] [blame] | 2462 | 'Scheduling CQ dry run on: https://codereview.chromium.org/123\n') |
tandrii | 9de9ec6 | 2016-07-13 03:01:59 -0700 | [diff] [blame] | 2463 | |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2464 | def test_git_cl_try_default_cq_dry_run_gerrit(self): |
| 2465 | self.mock(git_cl.Changelist, 'GetChange', |
| 2466 | lambda _, *a: ( |
| 2467 | self._mocked_call(['GetChange']+list(a)))) |
| 2468 | self.mock(git_cl.presubmit_support, 'DoGetTryMasters', |
| 2469 | lambda *_, **__: ( |
| 2470 | self._mocked_call(['DoGetTryMasters']))) |
| 2471 | self.mock(git_cl._GerritChangelistImpl, 'SetCQState', |
| 2472 | lambda _, s: self._mocked_call(['SetCQState', s])) |
| 2473 | |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2474 | self.calls = [ |
| 2475 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2476 | ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 2477 | ((['git', 'config', 'branch.feature.gerritissue'],), '123456'), |
| 2478 | ((['git', 'config', 'branch.feature.gerritserver'],), |
| 2479 | 'https://chromium-review.googlesource.com'), |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 2480 | ((['git', 'config', 'branch.feature.merge'],), 'feature'), |
| 2481 | ((['git', 'config', 'branch.feature.remote'],), 'origin'), |
| 2482 | ((['git', 'config', 'remote.origin.url'],), |
| 2483 | 'https://chromium.googlesource.com/depot_tools'), |
| 2484 | (('GetChangeDetail', 'chromium-review.googlesource.com', |
| 2485 | 'depot_tools~123456', |
Andrii Shyshkalov | eadad92 | 2017-01-26 09:38:30 +0100 | [diff] [blame] | 2486 | ['DETAILED_ACCOUNTS', 'ALL_REVISIONS', 'CURRENT_COMMIT']), { |
| 2487 | 'project': 'depot_tools', |
| 2488 | 'status': 'OPEN', |
| 2489 | 'owner': {'email': 'owner@e.mail'}, |
| 2490 | 'revisions': { |
| 2491 | 'deadbeaf': { |
| 2492 | '_number': 6, |
| 2493 | }, |
| 2494 | 'beeeeeef': { |
| 2495 | '_number': 7, |
| 2496 | 'fetch': {'http': { |
| 2497 | 'url': 'https://chromium.googlesource.com/depot_tools', |
| 2498 | 'ref': 'refs/changes/56/123456/7' |
| 2499 | }}, |
| 2500 | }, |
| 2501 | }, |
| 2502 | }), |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2503 | ((['git', 'config', 'branch.feature.merge'],), 'feature'), |
| 2504 | ((['git', 'config', 'branch.feature.remote'],), 'origin'), |
| 2505 | ((['get_or_create_merge_base', 'feature', 'feature'],), |
| 2506 | 'fake_ancestor_sha'), |
| 2507 | ((['GetChange', 'fake_ancestor_sha', None], ), |
| 2508 | git_cl.presubmit_support.GitChange( |
| 2509 | '', '', '', '', '', '', '', '')), |
| 2510 | ((['git', 'rev-parse', '--show-cdup'],), '../'), |
| 2511 | ((['DoGetTryMasters'], ), None), |
| 2512 | ((['SetCQState', git_cl._CQState.DRY_RUN], ), None), |
| 2513 | ] |
| 2514 | out = StringIO.StringIO() |
| 2515 | self.mock(git_cl.sys, 'stdout', out) |
| 2516 | self.assertEqual(0, git_cl.main(['try'])) |
| 2517 | self.assertEqual( |
| 2518 | out.getvalue(), |
Quinten Yearsley | fc5fd92 | 2017-05-31 11:50:52 -0700 | [diff] [blame] | 2519 | 'Scheduling CQ dry run on: ' |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2520 | 'https://chromium-review.googlesource.com/123456\n') |
| 2521 | |
| 2522 | def test_git_cl_try_buildbucket_with_properties_rietveld(self): |
| 2523 | self.mock(git_cl._RietveldChangelistImpl, 'GetIssueProperties', |
| 2524 | lambda _: { |
| 2525 | 'owner_email': 'owner@e.mail', |
| 2526 | 'private': False, |
| 2527 | 'closed': False, |
| 2528 | 'project': 'depot_tools', |
| 2529 | 'patchsets': [20001], |
| 2530 | }) |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2531 | self.mock(git_cl.uuid, 'uuid4', lambda: 'uuid4') |
| 2532 | self.calls = [ |
| 2533 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2534 | ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
| 2535 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2536 | ((['git', 'config', 'rietveld.server'],), |
| 2537 | 'https://codereview.chromium.org'), |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2538 | ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2539 | ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2540 | ] |
| 2541 | |
| 2542 | def _buildbucket_retry(*_, **kw): |
| 2543 | # self.maxDiff = 10000 |
| 2544 | body = json.loads(kw['body']) |
| 2545 | self.assertEqual(len(body['builds']), 1) |
| 2546 | build = body['builds'][0] |
| 2547 | params = json.loads(build.pop('parameters_json')) |
| 2548 | self.assertEqual(params, { |
| 2549 | u'builder_name': u'win', |
| 2550 | u'changes': [{u'author': {u'email': u'owner@e.mail'}, |
| 2551 | u'revision': None}], |
| 2552 | u'properties': { |
| 2553 | u'category': u'git_cl_try', |
| 2554 | u'issue': 123, |
| 2555 | u'key': u'val', |
| 2556 | u'json': [{u'a': 1}, None], |
| 2557 | u'master': u'tryserver.chromium', |
| 2558 | u'patch_project': u'depot_tools', |
| 2559 | u'patch_storage': u'rietveld', |
| 2560 | u'patchset': 20001, |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2561 | u'rietveld': u'https://codereview.chromium.org', |
| 2562 | } |
| 2563 | }) |
| 2564 | self.assertEqual(build, { |
| 2565 | u'bucket': u'master.tryserver.chromium', |
| 2566 | u'client_operation_id': u'uuid4', |
| 2567 | u'tags': [u'builder:win', |
| 2568 | u'buildset:patch/rietveld/codereview.chromium.org/123/20001', |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2569 | u'user_agent:git_cl_try', |
| 2570 | u'master:tryserver.chromium'], |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2571 | }) |
| 2572 | |
| 2573 | self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
| 2574 | |
| 2575 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2576 | self.assertEqual(0, git_cl.main([ |
| 2577 | 'try', '-m', 'tryserver.chromium', '-b', 'win', |
| 2578 | '-p', 'key=val', '-p', 'json=[{"a":1}, null]'])) |
| 2579 | self.assertRegexpMatches( |
| 2580 | git_cl.sys.stdout.getvalue(), |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2581 | 'Tried jobs on:\nBucket: master.tryserver.chromium') |
| 2582 | |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2583 | def test_git_cl_try_buildbucket_with_properties_gerrit(self): |
| 2584 | self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda _: 7) |
| 2585 | self.mock(git_cl.uuid, 'uuid4', lambda: 'uuid4') |
| 2586 | |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2587 | self.calls = [ |
| 2588 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2589 | ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 2590 | ((['git', 'config', 'branch.feature.gerritissue'],), '123456'), |
| 2591 | ((['git', 'config', 'branch.feature.gerritserver'],), |
| 2592 | 'https://chromium-review.googlesource.com'), |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 2593 | ((['git', 'config', 'branch.feature.merge'],), 'feature'), |
| 2594 | ((['git', 'config', 'branch.feature.remote'],), 'origin'), |
| 2595 | ((['git', 'config', 'remote.origin.url'],), |
| 2596 | 'https://chromium.googlesource.com/depot_tools'), |
| 2597 | (('GetChangeDetail', 'chromium-review.googlesource.com', |
| 2598 | 'depot_tools~123456', |
Andrii Shyshkalov | eadad92 | 2017-01-26 09:38:30 +0100 | [diff] [blame] | 2599 | ['DETAILED_ACCOUNTS', 'ALL_REVISIONS', 'CURRENT_COMMIT']), { |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2600 | 'project': 'depot_tools', |
Andrii Shyshkalov | eadad92 | 2017-01-26 09:38:30 +0100 | [diff] [blame] | 2601 | 'status': 'OPEN', |
| 2602 | 'owner': {'email': 'owner@e.mail'}, |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2603 | 'revisions': { |
| 2604 | 'deadbeaf': { |
| 2605 | '_number': 6, |
| 2606 | }, |
| 2607 | 'beeeeeef': { |
| 2608 | '_number': 7, |
| 2609 | 'fetch': {'http': { |
| 2610 | 'url': 'https://chromium.googlesource.com/depot_tools', |
| 2611 | 'ref': 'refs/changes/56/123456/7' |
| 2612 | }}, |
| 2613 | }, |
| 2614 | }, |
| 2615 | }), |
| 2616 | ] |
| 2617 | |
| 2618 | def _buildbucket_retry(*_, **kw): |
| 2619 | # self.maxDiff = 10000 |
| 2620 | body = json.loads(kw['body']) |
| 2621 | self.assertEqual(len(body['builds']), 1) |
| 2622 | build = body['builds'][0] |
| 2623 | params = json.loads(build.pop('parameters_json')) |
| 2624 | self.assertEqual(params, { |
| 2625 | u'builder_name': u'win', |
| 2626 | u'changes': [{u'author': {u'email': u'owner@e.mail'}, |
| 2627 | u'revision': None}], |
| 2628 | u'properties': { |
| 2629 | u'category': u'git_cl_try', |
| 2630 | u'key': u'val', |
| 2631 | u'json': [{u'a': 1}, None], |
| 2632 | u'master': u'tryserver.chromium', |
| 2633 | |
| 2634 | u'patch_gerrit_url': |
| 2635 | u'https://chromium-review.googlesource.com', |
| 2636 | u'patch_issue': 123456, |
| 2637 | u'patch_project': u'depot_tools', |
| 2638 | u'patch_ref': u'refs/changes/56/123456/7', |
| 2639 | u'patch_repository_url': |
| 2640 | u'https://chromium.googlesource.com/depot_tools', |
| 2641 | u'patch_set': 7, |
| 2642 | u'patch_storage': u'gerrit', |
| 2643 | } |
| 2644 | }) |
| 2645 | self.assertEqual(build, { |
| 2646 | u'bucket': u'master.tryserver.chromium', |
| 2647 | u'client_operation_id': u'uuid4', |
| 2648 | u'tags': [ |
| 2649 | u'builder:win', |
| 2650 | u'buildset:patch/gerrit/chromium-review.googlesource.com/123456/7', |
| 2651 | u'user_agent:git_cl_try', |
| 2652 | u'master:tryserver.chromium'], |
| 2653 | }) |
| 2654 | |
| 2655 | self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
| 2656 | |
| 2657 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2658 | self.assertEqual(0, git_cl.main([ |
| 2659 | 'try', '-m', 'tryserver.chromium', '-b', 'win', |
| 2660 | '-p', 'key=val', '-p', 'json=[{"a":1}, null]'])) |
| 2661 | self.assertRegexpMatches( |
| 2662 | git_cl.sys.stdout.getvalue(), |
| 2663 | 'Tried jobs on:\nBucket: master.tryserver.chromium') |
| 2664 | |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2665 | def test_git_cl_try_buildbucket_bucket_flag(self): |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2666 | self.mock(git_cl._RietveldChangelistImpl, 'GetIssueProperties', |
| 2667 | lambda _: { |
| 2668 | 'owner_email': 'owner@e.mail', |
| 2669 | 'private': False, |
| 2670 | 'closed': False, |
| 2671 | 'project': 'depot_tools', |
| 2672 | 'patchsets': [20001], |
| 2673 | }) |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2674 | self.mock(git_cl.uuid, 'uuid4', lambda: 'uuid4') |
| 2675 | self.calls = [ |
| 2676 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2677 | ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
| 2678 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2679 | ((['git', 'config', 'rietveld.server'],), |
| 2680 | 'https://codereview.chromium.org'), |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2681 | ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2682 | ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2683 | ] |
| 2684 | |
| 2685 | def _buildbucket_retry(*_, **kw): |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2686 | body = json.loads(kw['body']) |
| 2687 | self.assertEqual(len(body['builds']), 1) |
| 2688 | build = body['builds'][0] |
| 2689 | params = json.loads(build.pop('parameters_json')) |
| 2690 | self.assertEqual(params, { |
| 2691 | u'builder_name': u'win', |
| 2692 | u'changes': [{u'author': {u'email': u'owner@e.mail'}, |
| 2693 | u'revision': None}], |
| 2694 | u'properties': { |
| 2695 | u'category': u'git_cl_try', |
| 2696 | u'issue': 123, |
| 2697 | u'patch_project': u'depot_tools', |
| 2698 | u'patch_storage': u'rietveld', |
| 2699 | u'patchset': 20001, |
borenet | 6c0efe6 | 2016-10-19 08:13:29 -0700 | [diff] [blame] | 2700 | u'rietveld': u'https://codereview.chromium.org', |
| 2701 | } |
| 2702 | }) |
| 2703 | self.assertEqual(build, { |
| 2704 | u'bucket': u'test.bucket', |
| 2705 | u'client_operation_id': u'uuid4', |
| 2706 | u'tags': [u'builder:win', |
| 2707 | u'buildset:patch/rietveld/codereview.chromium.org/123/20001', |
| 2708 | u'user_agent:git_cl_try'], |
| 2709 | }) |
| 2710 | |
| 2711 | self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
| 2712 | |
| 2713 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2714 | self.assertEqual(0, git_cl.main([ |
| 2715 | 'try', '-B', 'test.bucket', '-b', 'win'])) |
| 2716 | self.assertRegexpMatches( |
| 2717 | git_cl.sys.stdout.getvalue(), |
| 2718 | 'Tried jobs on:\nBucket: test.bucket') |
tandrii | de281ae | 2016-10-12 06:02:30 -0700 | [diff] [blame] | 2719 | |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2720 | def test_git_cl_try_bots_on_multiple_masters(self): |
| 2721 | self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda _: 20001) |
| 2722 | self.calls = [ |
| 2723 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2724 | ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), |
| 2725 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2726 | ((['git', 'config', 'rietveld.server'],), |
tandrii | 8c5a353 | 2016-11-04 07:52:02 -0700 | [diff] [blame] | 2727 | 'https://codereview.chromium.org'), |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2728 | ((['git', 'config', 'branch.feature.rietveldserver'],), CERR1), |
| 2729 | ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
| 2730 | ] |
| 2731 | |
| 2732 | def _buildbucket_retry(*_, **kw): |
| 2733 | body = json.loads(kw['body']) |
| 2734 | self.assertEqual(len(body['builds']), 2) |
| 2735 | |
Nodir Turakulov | b422e68 | 2018-02-20 22:51:30 -0800 | [diff] [blame] | 2736 | self.assertEqual(body['builds'][0]['bucket'], 'bucket1') |
| 2737 | params = json.loads(body['builds'][0]['parameters_json']) |
| 2738 | self.assertEqual(params['builder_name'], 'builder1') |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2739 | |
Nodir Turakulov | b422e68 | 2018-02-20 22:51:30 -0800 | [diff] [blame] | 2740 | self.assertEqual(body['builds'][1]['bucket'], 'bucket2') |
| 2741 | params = json.loads(body['builds'][1]['parameters_json']) |
| 2742 | self.assertEqual(params['builder_name'], 'builder2') |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2743 | |
| 2744 | self.mock(git_cl, '_buildbucket_retry', _buildbucket_retry) |
| 2745 | |
| 2746 | self.mock(git_cl.urllib2, 'urlopen', lambda _: StringIO.StringIO( |
Nodir Turakulov | b422e68 | 2018-02-20 22:51:30 -0800 | [diff] [blame] | 2747 | json.dumps({ |
| 2748 | 'builder1': {'bucket': 'bucket1'}, |
| 2749 | 'builder2': {'bucket': 'bucket2'}, |
| 2750 | }))) |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2751 | |
| 2752 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2753 | self.assertEqual( |
| 2754 | 0, git_cl.main(['try', '-b', 'builder1', '-b', 'builder2'])) |
| 2755 | self.assertEqual( |
| 2756 | git_cl.sys.stdout.getvalue(), |
| 2757 | 'Tried jobs on:\n' |
Nodir Turakulov | b422e68 | 2018-02-20 22:51:30 -0800 | [diff] [blame] | 2758 | 'Bucket: bucket1\n' |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2759 | ' builder1: []\n' |
Nodir Turakulov | b422e68 | 2018-02-20 22:51:30 -0800 | [diff] [blame] | 2760 | 'Bucket: bucket2\n' |
qyearsley | 123a468 | 2016-10-26 09:12:17 -0700 | [diff] [blame] | 2761 | ' builder2: []\n' |
| 2762 | 'To see results here, run: git cl try-results\n' |
| 2763 | 'To see results in browser, run: git cl web\n') |
| 2764 | |
tandrii | 16e0b4e | 2016-06-07 10:34:28 -0700 | [diff] [blame] | 2765 | def _common_GerritCommitMsgHookCheck(self): |
| 2766 | self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
| 2767 | self.mock(git_cl.os.path, 'abspath', |
| 2768 | lambda path: self._mocked_call(['abspath', path])) |
| 2769 | self.mock(git_cl.os.path, 'exists', |
| 2770 | lambda path: self._mocked_call(['exists', path])) |
| 2771 | self.mock(git_cl.gclient_utils, 'FileRead', |
| 2772 | lambda path: self._mocked_call(['FileRead', path])) |
| 2773 | self.mock(git_cl.gclient_utils, 'rm_file_or_tree', |
| 2774 | lambda path: self._mocked_call(['rm_file_or_tree', path])) |
| 2775 | self.calls = [ |
| 2776 | ((['git', 'rev-parse', '--show-cdup'],), '../'), |
| 2777 | ((['abspath', '../'],), '/abs/git_repo_root'), |
| 2778 | ] |
| 2779 | return git_cl.Changelist(codereview='gerrit', issue=123) |
| 2780 | |
| 2781 | def test_GerritCommitMsgHookCheck_custom_hook(self): |
| 2782 | cl = self._common_GerritCommitMsgHookCheck() |
| 2783 | self.calls += [ |
| 2784 | ((['exists', '/abs/git_repo_root/.git/hooks/commit-msg'],), True), |
| 2785 | ((['FileRead', '/abs/git_repo_root/.git/hooks/commit-msg'],), |
| 2786 | '#!/bin/sh\necho "custom hook"') |
| 2787 | ] |
| 2788 | cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) |
| 2789 | |
| 2790 | def test_GerritCommitMsgHookCheck_not_exists(self): |
| 2791 | cl = self._common_GerritCommitMsgHookCheck() |
| 2792 | self.calls += [ |
| 2793 | ((['exists', '/abs/git_repo_root/.git/hooks/commit-msg'],), False), |
| 2794 | ] |
| 2795 | cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) |
| 2796 | |
| 2797 | def test_GerritCommitMsgHookCheck(self): |
| 2798 | cl = self._common_GerritCommitMsgHookCheck() |
| 2799 | self.calls += [ |
| 2800 | ((['exists', '/abs/git_repo_root/.git/hooks/commit-msg'],), True), |
| 2801 | ((['FileRead', '/abs/git_repo_root/.git/hooks/commit-msg'],), |
| 2802 | '...\n# From Gerrit Code Review\n...\nadd_ChangeId()\n'), |
Andrii Shyshkalov | abc26ac | 2017-03-14 14:49:38 +0100 | [diff] [blame] | 2803 | (('ask_for_data', 'Do you want to remove it now? [Yes/No]: '), 'Yes'), |
tandrii | 16e0b4e | 2016-06-07 10:34:28 -0700 | [diff] [blame] | 2804 | ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), |
| 2805 | ''), |
| 2806 | ] |
| 2807 | cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) |
| 2808 | |
tandrii | c4344b5 | 2016-08-29 06:04:54 -0700 | [diff] [blame] | 2809 | def test_GerritCmdLand(self): |
| 2810 | self.calls += [ |
| 2811 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2812 | ((['git', 'config', 'branch.feature.gerritsquashhash'],), |
| 2813 | 'deadbeaf'), |
| 2814 | ((['git', 'diff', 'deadbeaf'],), ''), # No diff. |
| 2815 | ((['git', 'config', 'branch.feature.gerritserver'],), |
| 2816 | 'chromium-review.googlesource.com'), |
| 2817 | ] |
| 2818 | cl = git_cl.Changelist(issue=123, codereview='gerrit') |
| 2819 | cl._codereview_impl._GetChangeDetail = lambda _: { |
| 2820 | 'labels': {}, |
| 2821 | 'current_revision': 'deadbeaf', |
| 2822 | } |
agable | 32978d9 | 2016-11-01 12:55:02 -0700 | [diff] [blame] | 2823 | cl._codereview_impl._GetChangeCommit = lambda: { |
| 2824 | 'commit': 'deadbeef', |
Aaron Gable | 02cdbb4 | 2016-12-13 16:24:25 -0800 | [diff] [blame] | 2825 | 'web_links': [{'name': 'gitiles', |
agable | 32978d9 | 2016-11-01 12:55:02 -0700 | [diff] [blame] | 2826 | 'url': 'https://git.googlesource.com/test/+/deadbeef'}], |
| 2827 | } |
tandrii | c4344b5 | 2016-08-29 06:04:54 -0700 | [diff] [blame] | 2828 | cl._codereview_impl.SubmitIssue = lambda wait_for_merge: None |
tandrii | 8da412c | 2016-09-07 16:01:07 -0700 | [diff] [blame] | 2829 | out = StringIO.StringIO() |
| 2830 | self.mock(sys, 'stdout', out) |
Olivier Robin | 75ee725 | 2018-04-13 10:02:56 +0200 | [diff] [blame] | 2831 | self.assertEqual(0, cl.CMDLand(force=True, |
| 2832 | bypass_hooks=True, |
| 2833 | verbose=True, |
| 2834 | parallel=False)) |
tandrii | 8da412c | 2016-09-07 16:01:07 -0700 | [diff] [blame] | 2835 | self.assertRegexpMatches(out.getvalue(), 'Issue.*123 has been submitted') |
Quinten Yearsley | 0c62da9 | 2017-05-31 13:39:42 -0700 | [diff] [blame] | 2836 | self.assertRegexpMatches(out.getvalue(), 'Landed as: .*deadbeef') |
tandrii | c4344b5 | 2016-08-29 06:04:54 -0700 | [diff] [blame] | 2837 | |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2838 | BUILDBUCKET_BUILDS_MAP = { |
Quinten Yearsley | a563d72 | 2017-12-11 16:36:54 -0800 | [diff] [blame] | 2839 | '9000': { |
| 2840 | 'id': '9000', |
| 2841 | 'bucket': 'master.x.y', |
| 2842 | 'created_by': 'user:someone@chromium.org', |
| 2843 | 'created_ts': '147200002222000', |
| 2844 | 'experimental': False, |
| 2845 | 'parameters_json': json.dumps({ |
| 2846 | 'builder_name': 'my-bot', |
| 2847 | 'properties': {'category': 'cq'}, |
| 2848 | }), |
| 2849 | 'status': 'STARTED', |
| 2850 | 'tags': [ |
| 2851 | 'build_address:x.y/my-bot/2', |
| 2852 | 'builder:my-bot', |
| 2853 | 'experimental:false', |
| 2854 | 'user_agent:cq', |
| 2855 | ], |
| 2856 | 'url': 'http://build.cr.org/p/x.y/builders/my-bot/builds/2', |
| 2857 | }, |
| 2858 | '8000': { |
| 2859 | 'id': '8000', |
| 2860 | 'bucket': 'master.x.y', |
| 2861 | 'created_by': 'user:someone@chromium.org', |
| 2862 | 'created_ts': '147200001111000', |
| 2863 | 'experimental': False, |
| 2864 | 'failure_reason': 'BUILD_FAILURE', |
| 2865 | 'parameters_json': json.dumps({ |
| 2866 | 'builder_name': 'my-bot', |
| 2867 | 'properties': {'category': 'cq'}, |
| 2868 | }), |
| 2869 | 'result_details_json': json.dumps({ |
| 2870 | 'properties': {'buildnumber': 1}, |
| 2871 | }), |
| 2872 | 'result': 'FAILURE', |
| 2873 | 'status': 'COMPLETED', |
| 2874 | 'tags': [ |
| 2875 | 'build_address:x.y/my-bot/1', |
| 2876 | 'builder:my-bot', |
| 2877 | 'experimental:false', |
| 2878 | 'user_agent:cq', |
| 2879 | ], |
| 2880 | 'url': 'http://build.cr.org/p/x.y/builders/my-bot/builds/1', |
| 2881 | }, |
| 2882 | } |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2883 | |
| 2884 | def test_write_try_results_json(self): |
| 2885 | expected_output = [ |
Quinten Yearsley | a563d72 | 2017-12-11 16:36:54 -0800 | [diff] [blame] | 2886 | { |
| 2887 | 'bucket': 'master.x.y', |
| 2888 | 'buildbucket_id': '8000', |
| 2889 | 'builder_name': 'my-bot', |
| 2890 | 'created_ts': '147200001111000', |
| 2891 | 'experimental': False, |
| 2892 | 'failure_reason': 'BUILD_FAILURE', |
| 2893 | 'result': 'FAILURE', |
| 2894 | 'status': 'COMPLETED', |
| 2895 | 'tags': [ |
| 2896 | 'build_address:x.y/my-bot/1', |
| 2897 | 'builder:my-bot', |
| 2898 | 'experimental:false', |
| 2899 | 'user_agent:cq', |
| 2900 | ], |
| 2901 | 'url': 'http://build.cr.org/p/x.y/builders/my-bot/builds/1', |
| 2902 | }, |
| 2903 | { |
| 2904 | 'bucket': 'master.x.y', |
| 2905 | 'buildbucket_id': '9000', |
| 2906 | 'builder_name': 'my-bot', |
| 2907 | 'created_ts': '147200002222000', |
| 2908 | 'experimental': False, |
| 2909 | 'failure_reason': None, |
| 2910 | 'result': None, |
| 2911 | 'status': 'STARTED', |
| 2912 | 'tags': [ |
| 2913 | 'build_address:x.y/my-bot/2', |
| 2914 | 'builder:my-bot', |
| 2915 | 'experimental:false', |
| 2916 | 'user_agent:cq', |
| 2917 | ], |
| 2918 | 'url': 'http://build.cr.org/p/x.y/builders/my-bot/builds/2', |
| 2919 | }, |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2920 | ] |
| 2921 | self.calls = [(('write_json', 'output.json', expected_output), '')] |
| 2922 | git_cl.write_try_results_json('output.json', self.BUILDBUCKET_BUILDS_MAP) |
| 2923 | |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2924 | def _setup_fetch_try_jobs(self, most_recent_patchset=20001): |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2925 | out = StringIO.StringIO() |
| 2926 | self.mock(sys, 'stdout', out) |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2927 | self.mock(git_cl.Changelist, 'GetMostRecentPatchset', |
| 2928 | lambda *args: most_recent_patchset) |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2929 | self.mock(git_cl.auth, 'get_authenticator_for_host', lambda host, _cfg: |
| 2930 | self._mocked_call(['get_authenticator_for_host', host])) |
| 2931 | self.mock(git_cl, '_buildbucket_retry', lambda *_, **__: |
| 2932 | self._mocked_call(['_buildbucket_retry'])) |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2933 | |
| 2934 | def _setup_fetch_try_jobs_rietveld(self, *request_results): |
| 2935 | self._setup_fetch_try_jobs(most_recent_patchset=20001) |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2936 | self.calls += [ |
| 2937 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2938 | ((['git', 'config', 'branch.feature.rietveldissue'],), '1'), |
| 2939 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 2940 | ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
| 2941 | ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), |
| 2942 | ((['git', 'config', 'branch.feature.rietveldserver'],), |
| 2943 | 'codereview.example.com'), |
| 2944 | ((['get_authenticator_for_host', 'codereview.example.com'],), |
| 2945 | AuthenticatorMock()), |
| 2946 | ] + [((['_buildbucket_retry'],), r) for r in request_results] |
| 2947 | |
| 2948 | def test_fetch_try_jobs_none_rietveld(self): |
| 2949 | self._setup_fetch_try_jobs_rietveld({}) |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2950 | # Simulate that user isn't logged in. |
| 2951 | self.mock(AuthenticatorMock, 'has_cached_credentials', lambda _: False) |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2952 | self.assertEqual(0, git_cl.main(['try-results'])) |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2953 | self.assertRegexpMatches(sys.stdout.getvalue(), |
| 2954 | 'Warning: Some results might be missing') |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 2955 | self.assertRegexpMatches(sys.stdout.getvalue(), 'No try jobs') |
| 2956 | |
| 2957 | def test_fetch_try_jobs_some_rietveld(self): |
| 2958 | self._setup_fetch_try_jobs_rietveld({ |
| 2959 | 'builds': self.BUILDBUCKET_BUILDS_MAP.values(), |
| 2960 | }) |
| 2961 | self.assertEqual(0, git_cl.main(['try-results'])) |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2962 | self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') |
| 2963 | self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') |
| 2964 | self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') |
| 2965 | |
| 2966 | def _setup_fetch_try_jobs_gerrit(self, *request_results): |
| 2967 | self._setup_fetch_try_jobs(most_recent_patchset=13) |
| 2968 | self.calls += [ |
| 2969 | ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), |
| 2970 | ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1), |
| 2971 | ((['git', 'config', 'branch.feature.gerritissue'],), '1'), |
Ravi Mistry | fda50ca | 2016-11-14 10:19:18 -0500 | [diff] [blame] | 2972 | # TODO(tandrii): Uncomment the below if we decide to support checking |
| 2973 | # patchsets for Gerrit. |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2974 | # Simulate that Gerrit has more patchsets than local. |
Ravi Mistry | fda50ca | 2016-11-14 10:19:18 -0500 | [diff] [blame] | 2975 | # ((['git', 'config', 'branch.feature.gerritpatchset'],), '12'), |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2976 | ((['git', 'config', 'branch.feature.gerritserver'],), |
| 2977 | 'https://x-review.googlesource.com'), |
| 2978 | ((['get_authenticator_for_host', 'x-review.googlesource.com'],), |
| 2979 | AuthenticatorMock()), |
| 2980 | ] + [((['_buildbucket_retry'],), r) for r in request_results] |
| 2981 | |
| 2982 | def test_fetch_try_jobs_none_gerrit(self): |
| 2983 | self._setup_fetch_try_jobs_gerrit({}) |
| 2984 | self.assertEqual(0, git_cl.main(['try-results'])) |
Ravi Mistry | fda50ca | 2016-11-14 10:19:18 -0500 | [diff] [blame] | 2985 | # TODO(tandrii): Uncomment the below if we decide to support checking |
| 2986 | # patchsets for Gerrit. |
| 2987 | # self.assertRegexpMatches( |
| 2988 | # sys.stdout.getvalue(), |
| 2989 | # r'Warning: Codereview server has newer patchsets \(13\)') |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 2990 | self.assertRegexpMatches(sys.stdout.getvalue(), 'No try jobs') |
| 2991 | |
| 2992 | def test_fetch_try_jobs_some_gerrit(self): |
| 2993 | self._setup_fetch_try_jobs_gerrit({ |
| 2994 | 'builds': self.BUILDBUCKET_BUILDS_MAP.values(), |
| 2995 | }) |
Ravi Mistry | fda50ca | 2016-11-14 10:19:18 -0500 | [diff] [blame] | 2996 | # TODO(tandrii): Uncomment the below if we decide to support checking |
| 2997 | # patchsets for Gerrit. |
| 2998 | # self.calls.remove( |
| 2999 | # ((['git', 'config', 'branch.feature.gerritpatchset'],), '12')) |
tandrii | 45b2a58 | 2016-10-11 03:14:16 -0700 | [diff] [blame] | 3000 | self.assertEqual(0, git_cl.main(['try-results', '--patchset', '5'])) |
| 3001 | |
| 3002 | # ... and doesn't result in warning. |
| 3003 | self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') |
| 3004 | self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') |
tandrii | 221ab25 | 2016-10-06 08:12:04 -0700 | [diff] [blame] | 3005 | self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') |
| 3006 | self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') |
| 3007 | |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3008 | def _mock_gerrit_changes_for_detail_cache(self): |
| 3009 | self.mock(git_cl._GerritChangelistImpl, '_GetGerritHost', lambda _: 'host') |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3010 | |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3011 | def test_gerrit_change_detail_cache_simple(self): |
| 3012 | self._mock_gerrit_changes_for_detail_cache() |
| 3013 | self.calls = [ |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3014 | (('GetChangeDetail', 'host', 'my%2Frepo~1', []), 'a'), |
| 3015 | (('GetChangeDetail', 'host', 'ab%2Frepo~2', []), 'b'), |
| 3016 | (('GetChangeDetail', 'host', 'ab%2Frepo~2', []), 'b2'), |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3017 | ] |
Andrii Shyshkalov | b721460 | 2018-08-22 23:20:26 +0000 | [diff] [blame] | 3018 | cl1 = git_cl.Changelist(issue=1, codereview='gerrit') |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3019 | cl1._cached_remote_url = ( |
| 3020 | True, 'https://chromium.googlesource.com/a/my/repo.git/') |
Andrii Shyshkalov | b721460 | 2018-08-22 23:20:26 +0000 | [diff] [blame] | 3021 | cl2 = git_cl.Changelist(issue=2, codereview='gerrit') |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3022 | cl2._cached_remote_url = ( |
| 3023 | True, 'https://chromium.googlesource.com/ab/repo') |
Andrii Shyshkalov | b721460 | 2018-08-22 23:20:26 +0000 | [diff] [blame] | 3024 | self.assertEqual(cl1._GetChangeDetail(), 'a') # Miss. |
| 3025 | self.assertEqual(cl1._GetChangeDetail(), 'a') |
| 3026 | self.assertEqual(cl2._GetChangeDetail(), 'b') # Miss. |
| 3027 | self.assertEqual(cl2._GetChangeDetail(no_cache=True), 'b2') # Miss. |
| 3028 | self.assertEqual(cl1._GetChangeDetail(), 'a') |
| 3029 | self.assertEqual(cl2._GetChangeDetail(), 'b2') |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3030 | |
| 3031 | def test_gerrit_change_detail_cache_options(self): |
| 3032 | self._mock_gerrit_changes_for_detail_cache() |
| 3033 | self.calls = [ |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3034 | (('GetChangeDetail', 'host', 'repo~1', ['C', 'A', 'B']), 'cab'), |
| 3035 | (('GetChangeDetail', 'host', 'repo~1', ['A', 'D']), 'ad'), |
| 3036 | (('GetChangeDetail', 'host', 'repo~1', ['A']), 'a'), # no_cache=True |
| 3037 | # no longer in cache. |
| 3038 | (('GetChangeDetail', 'host', 'repo~1', ['B']), 'b'), |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3039 | ] |
| 3040 | cl = git_cl.Changelist(issue=1, codereview='gerrit') |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3041 | cl._cached_remote_url = (True, 'https://chromium.googlesource.com/repo/') |
Andrii Shyshkalov | 258e0a6 | 2017-01-24 16:50:57 +0100 | [diff] [blame] | 3042 | self.assertEqual(cl._GetChangeDetail(options=['C', 'A', 'B']), 'cab') |
| 3043 | self.assertEqual(cl._GetChangeDetail(options=['A', 'B', 'C']), 'cab') |
| 3044 | self.assertEqual(cl._GetChangeDetail(options=['B', 'A']), 'cab') |
| 3045 | self.assertEqual(cl._GetChangeDetail(options=['C']), 'cab') |
| 3046 | self.assertEqual(cl._GetChangeDetail(options=['A']), 'cab') |
| 3047 | self.assertEqual(cl._GetChangeDetail(), 'cab') |
| 3048 | |
| 3049 | self.assertEqual(cl._GetChangeDetail(options=['A', 'D']), 'ad') |
| 3050 | self.assertEqual(cl._GetChangeDetail(options=['A']), 'cab') |
| 3051 | self.assertEqual(cl._GetChangeDetail(options=['D']), 'ad') |
| 3052 | self.assertEqual(cl._GetChangeDetail(), 'cab') |
| 3053 | |
| 3054 | # Finally, no_cache should invalidate all caches for given change. |
| 3055 | self.assertEqual(cl._GetChangeDetail(options=['A'], no_cache=True), 'a') |
| 3056 | self.assertEqual(cl._GetChangeDetail(options=['B']), 'b') |
| 3057 | |
Andrii Shyshkalov | 21fb824 | 2017-02-15 21:09:27 +0100 | [diff] [blame] | 3058 | def test_gerrit_description_caching(self): |
| 3059 | def gen_detail(rev, desc): |
| 3060 | return { |
| 3061 | 'current_revision': rev, |
| 3062 | 'revisions': {rev: {'commit': {'message': desc}}} |
| 3063 | } |
| 3064 | self.calls = [ |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3065 | (('GetChangeDetail', 'host', 'my%2Frepo~1', |
Andrii Shyshkalov | 21fb824 | 2017-02-15 21:09:27 +0100 | [diff] [blame] | 3066 | ['CURRENT_REVISION', 'CURRENT_COMMIT']), |
| 3067 | gen_detail('rev1', 'desc1')), |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3068 | (('GetChangeDetail', 'host', 'my%2Frepo~1', |
Andrii Shyshkalov | 21fb824 | 2017-02-15 21:09:27 +0100 | [diff] [blame] | 3069 | ['CURRENT_REVISION', 'CURRENT_COMMIT']), |
| 3070 | gen_detail('rev2', 'desc2')), |
| 3071 | ] |
| 3072 | |
| 3073 | self._mock_gerrit_changes_for_detail_cache() |
| 3074 | cl = git_cl.Changelist(issue=1, codereview='gerrit') |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3075 | cl._cached_remote_url = ( |
| 3076 | True, 'https://chromium.googlesource.com/a/my/repo.git/') |
Andrii Shyshkalov | 21fb824 | 2017-02-15 21:09:27 +0100 | [diff] [blame] | 3077 | self.assertEqual(cl.GetDescription(), 'desc1') |
| 3078 | self.assertEqual(cl.GetDescription(), 'desc1') # cache hit. |
| 3079 | self.assertEqual(cl.GetDescription(force=True), 'desc2') |
tandrii@chromium.org | f86c7d3 | 2016-04-01 19:27:30 +0000 | [diff] [blame] | 3080 | |
Andrii Shyshkalov | 34924cd | 2017-03-15 17:08:32 +0100 | [diff] [blame] | 3081 | def test_print_current_creds(self): |
| 3082 | class CookiesAuthenticatorMock(object): |
| 3083 | def __init__(self): |
| 3084 | self.gitcookies = { |
| 3085 | 'host.googlesource.com': ('user', 'pass'), |
| 3086 | 'host-review.googlesource.com': ('user', 'pass'), |
| 3087 | } |
| 3088 | self.netrc = self |
| 3089 | self.netrc.hosts = { |
| 3090 | 'github.com': ('user2', None, 'pass2'), |
| 3091 | 'host2.googlesource.com': ('user3', None, 'pass'), |
| 3092 | } |
| 3093 | self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', |
| 3094 | CookiesAuthenticatorMock) |
| 3095 | self.mock(sys, 'stdout', StringIO.StringIO()) |
| 3096 | git_cl._GitCookiesChecker().print_current_creds(include_netrc=True) |
| 3097 | self.assertEqual(list(sys.stdout.getvalue().splitlines()), [ |
| 3098 | ' Host\t User\t Which file', |
| 3099 | '============================\t=====\t===========', |
| 3100 | 'host-review.googlesource.com\t user\t.gitcookies', |
| 3101 | ' host.googlesource.com\t user\t.gitcookies', |
| 3102 | ' host2.googlesource.com\tuser3\t .netrc', |
| 3103 | ]) |
| 3104 | sys.stdout.buf = '' |
| 3105 | git_cl._GitCookiesChecker().print_current_creds(include_netrc=False) |
| 3106 | self.assertEqual(list(sys.stdout.getvalue().splitlines()), [ |
| 3107 | ' Host\tUser\t Which file', |
| 3108 | '============================\t====\t===========', |
| 3109 | 'host-review.googlesource.com\tuser\t.gitcookies', |
| 3110 | ' host.googlesource.com\tuser\t.gitcookies', |
| 3111 | ]) |
| 3112 | |
Andrii Shyshkalov | 353637c | 2017-03-14 16:52:18 +0100 | [diff] [blame] | 3113 | def _common_creds_check_mocks(self): |
| 3114 | def exists_mock(path): |
| 3115 | dirname = os.path.dirname(path) |
| 3116 | if dirname == os.path.expanduser('~'): |
| 3117 | dirname = '~' |
| 3118 | base = os.path.basename(path) |
| 3119 | if base in ('.netrc', '.gitcookies'): |
| 3120 | return self._mocked_call('os.path.exists', '%s/%s' % (dirname, base)) |
| 3121 | # git cl also checks for existence other files not relevant to this test. |
| 3122 | return None |
| 3123 | self.mock(os.path, 'exists', exists_mock) |
| 3124 | self.mock(sys, 'stdout', StringIO.StringIO()) |
| 3125 | |
| 3126 | def test_creds_check_gitcookies_not_configured(self): |
| 3127 | self._common_creds_check_mocks() |
Andrii Shyshkalov | 34924cd | 2017-03-15 17:08:32 +0100 | [diff] [blame] | 3128 | self.mock(git_cl._GitCookiesChecker, 'get_hosts_with_creds', |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 3129 | lambda _, include_netrc=False: []) |
Andrii Shyshkalov | 353637c | 2017-03-14 16:52:18 +0100 | [diff] [blame] | 3130 | self.calls = [ |
Aaron Gable | 8797cab | 2018-03-06 13:55:00 -0800 | [diff] [blame] | 3131 | ((['git', 'config', '--path', 'http.cookiefile'],), CERR1), |
Andrii Shyshkalov | 353637c | 2017-03-14 16:52:18 +0100 | [diff] [blame] | 3132 | ((['git', 'config', '--global', 'http.cookiefile'],), CERR1), |
| 3133 | (('os.path.exists', '~/.netrc'), True), |
| 3134 | (('ask_for_data', 'Press Enter to setup .gitcookies, ' |
| 3135 | 'or Ctrl+C to abort'), ''), |
| 3136 | ((['git', 'config', '--global', 'http.cookiefile', |
| 3137 | os.path.expanduser('~/.gitcookies')], ), ''), |
| 3138 | ] |
| 3139 | self.assertEqual(0, git_cl.main(['creds-check'])) |
| 3140 | self.assertRegexpMatches( |
| 3141 | sys.stdout.getvalue(), |
| 3142 | '^You seem to be using outdated .netrc for git credentials:') |
| 3143 | self.assertRegexpMatches( |
| 3144 | sys.stdout.getvalue(), |
| 3145 | '\nConfigured git to use .gitcookies from') |
| 3146 | |
| 3147 | def test_creds_check_gitcookies_configured_custom_broken(self): |
| 3148 | self._common_creds_check_mocks() |
Andrii Shyshkalov | 34924cd | 2017-03-15 17:08:32 +0100 | [diff] [blame] | 3149 | self.mock(git_cl._GitCookiesChecker, 'get_hosts_with_creds', |
Andrii Shyshkalov | 0a0b067 | 2017-03-16 16:27:48 +0100 | [diff] [blame] | 3150 | lambda _, include_netrc=False: []) |
Andrii Shyshkalov | 353637c | 2017-03-14 16:52:18 +0100 | [diff] [blame] | 3151 | self.calls = [ |
Aaron Gable | 8797cab | 2018-03-06 13:55:00 -0800 | [diff] [blame] | 3152 | ((['git', 'config', '--path', 'http.cookiefile'],), CERR1), |
Andrii Shyshkalov | 353637c | 2017-03-14 16:52:18 +0100 | [diff] [blame] | 3153 | ((['git', 'config', '--global', 'http.cookiefile'],), |
| 3154 | '/custom/.gitcookies'), |
| 3155 | (('os.path.exists', '/custom/.gitcookies'), False), |
| 3156 | (('ask_for_data', 'Reconfigure git to use default .gitcookies? ' |
| 3157 | 'Press Enter to reconfigure, or Ctrl+C to abort'), ''), |
| 3158 | ((['git', 'config', '--global', 'http.cookiefile', |
| 3159 | os.path.expanduser('~/.gitcookies')], ), ''), |
| 3160 | ] |
| 3161 | self.assertEqual(0, git_cl.main(['creds-check'])) |
| 3162 | self.assertRegexpMatches( |
| 3163 | sys.stdout.getvalue(), |
Quinten Yearsley | 0c62da9 | 2017-05-31 13:39:42 -0700 | [diff] [blame] | 3164 | 'WARNING: You have configured custom path to .gitcookies: ') |
Andrii Shyshkalov | 353637c | 2017-03-14 16:52:18 +0100 | [diff] [blame] | 3165 | self.assertRegexpMatches( |
| 3166 | sys.stdout.getvalue(), |
| 3167 | 'However, your configured .gitcookies file is missing.') |
| 3168 | |
Andrii Shyshkalov | 0d6b46e | 2017-03-17 22:23:22 +0100 | [diff] [blame] | 3169 | def test_git_cl_comment_add_rietveld(self): |
Andrii Shyshkalov | 625986d | 2017-03-16 00:24:37 +0100 | [diff] [blame] | 3170 | self.mock(git_cl._RietveldChangelistImpl, 'AddComment', |
Aaron Gable | 636b13f | 2017-07-14 10:42:48 -0700 | [diff] [blame] | 3171 | lambda _, message, publish: self._mocked_call( |
| 3172 | 'AddComment', message, publish)) |
Andrii Shyshkalov | 625986d | 2017-03-16 00:24:37 +0100 | [diff] [blame] | 3173 | self.calls = [ |
| 3174 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 3175 | ((['git', 'config', 'rietveld.server'],), 'codereview.chromium.org'), |
Aaron Gable | 636b13f | 2017-07-14 10:42:48 -0700 | [diff] [blame] | 3176 | (('AddComment', 'msg', None), ''), |
Andrii Shyshkalov | 625986d | 2017-03-16 00:24:37 +0100 | [diff] [blame] | 3177 | ] |
Andrii Shyshkalov | 0d6b46e | 2017-03-17 22:23:22 +0100 | [diff] [blame] | 3178 | self.assertEqual(0, git_cl.main(['comment', '--rietveld', |
| 3179 | '-i', '10', '-a', 'msg'])) |
Andrii Shyshkalov | 625986d | 2017-03-16 00:24:37 +0100 | [diff] [blame] | 3180 | |
| 3181 | def test_git_cl_comment_add_gerrit(self): |
| 3182 | self.mock(git_cl.gerrit_util, 'SetReview', |
Aaron Gable | 636b13f | 2017-07-14 10:42:48 -0700 | [diff] [blame] | 3183 | lambda host, change, msg, ready: |
| 3184 | self._mocked_call('SetReview', host, change, msg, ready)) |
Andrii Shyshkalov | 625986d | 2017-03-16 00:24:37 +0100 | [diff] [blame] | 3185 | self.calls = [ |
| 3186 | ((['git', 'symbolic-ref', 'HEAD'],), CERR1), |
| 3187 | ((['git', 'symbolic-ref', 'HEAD'],), CERR1), |
| 3188 | ((['git', 'config', 'rietveld.upstream-branch'],), CERR1), |
| 3189 | ((['git', 'branch', '-r'],), 'origin/HEAD -> origin/master\n' |
| 3190 | 'origin/master'), |
| 3191 | ((['git', 'config', 'remote.origin.url'],), |
| 3192 | 'https://chromium.googlesource.com/infra/infra'), |
Andrii Shyshkalov | 889677c | 2018-08-28 20:43:06 +0000 | [diff] [blame] | 3193 | (('SetReview', 'chromium-review.googlesource.com', 'infra%2Finfra~10', |
| 3194 | 'msg', None), |
Aaron Gable | 636b13f | 2017-07-14 10:42:48 -0700 | [diff] [blame] | 3195 | None), |
Andrii Shyshkalov | 625986d | 2017-03-16 00:24:37 +0100 | [diff] [blame] | 3196 | ] |
| 3197 | self.assertEqual(0, git_cl.main(['comment', '--gerrit', '-i', '10', |
| 3198 | '-a', 'msg'])) |
| 3199 | |
Andrii Shyshkalov | d8aa49f | 2017-03-17 16:05:49 +0100 | [diff] [blame] | 3200 | def test_git_cl_comments_fetch_rietveld(self): |
| 3201 | self.mock(sys, 'stdout', StringIO.StringIO()) |
| 3202 | self.calls = [ |
| 3203 | ((['git', 'config', 'rietveld.autoupdate'],), CERR1), |
| 3204 | ((['git', 'config', 'rietveld.server'],), 'codereview.chromium.org'), |
Leszek Swirski | 45b20c4 | 2018-09-17 17:05:26 +0000 | [diff] [blame] | 3205 | ] * 2 + [ |
| 3206 | (('write_json', 'output.json', [ |
| 3207 | { |
| 3208 | 'date': '2000-03-13 20:49:34.515270', |
| 3209 | 'message': 'PTAL', |
| 3210 | 'approval': False, |
| 3211 | 'disapproval': False, |
| 3212 | 'sender': 'owner@example.com' |
| 3213 | }, { |
| 3214 | 'date': '2017-03-13 20:49:34.515270', |
| 3215 | 'message': 'lgtm', |
| 3216 | 'approval': True, |
| 3217 | 'disapproval': False, |
| 3218 | 'sender': 'r@example.com' |
| 3219 | }, { |
| 3220 | 'date': '2017-03-13 21:50:34.515270', |
| 3221 | 'message': 'not lgtm', |
| 3222 | 'approval': False, |
| 3223 | 'disapproval': True, |
| 3224 | 'sender': 'r2@example.com' |
| 3225 | } |
| 3226 | ]),'') |
| 3227 | ] |
Andrii Shyshkalov | d8aa49f | 2017-03-17 16:05:49 +0100 | [diff] [blame] | 3228 | self.mock(git_cl._RietveldChangelistImpl, 'GetIssueProperties', lambda _: { |
| 3229 | 'messages': [ |
| 3230 | {'text': 'lgtm', 'date': '2017-03-13 20:49:34.515270', |
| 3231 | 'disapproval': False, 'approval': True, 'sender': 'r@example.com'}, |
| 3232 | {'text': 'not lgtm', 'date': '2017-03-13 21:50:34.515270', |
| 3233 | 'disapproval': True, 'approval': False, 'sender': 'r2@example.com'}, |
| 3234 | # Intentionally wrong order here. |
| 3235 | {'text': 'PTAL', 'date': '2000-03-13 20:49:34.515270', |
| 3236 | 'disapproval': False, 'approval': False, |
| 3237 | 'sender': 'owner@example.com'}, |
| 3238 | ], |
| 3239 | 'owner_email': 'owner@example.com', |
| 3240 | }) |
| 3241 | expected_comments_summary = [ |
| 3242 | git_cl._CommentSummary( |
| 3243 | message='lgtm', |
| 3244 | date=datetime.datetime(2017, 3, 13, 20, 49, 34, 515270), |
| 3245 | disapproval=False, approval=True, sender='r@example.com'), |
| 3246 | git_cl._CommentSummary( |
| 3247 | message='not lgtm', |
| 3248 | date=datetime.datetime(2017, 3, 13, 21, 50, 34, 515270), |
| 3249 | disapproval=True, approval=False, sender='r2@example.com'), |
| 3250 | # Note: same order as in whatever Rietveld returns. |
| 3251 | git_cl._CommentSummary( |
| 3252 | message='PTAL', |
| 3253 | date=datetime.datetime(2000, 3, 13, 20, 49, 34, 515270), |
| 3254 | disapproval=False, approval=False, sender='owner@example.com'), |
| 3255 | ] |
| 3256 | cl = git_cl.Changelist(codereview='rietveld', issue=1) |
| 3257 | self.assertEqual(cl.GetCommentsSummary(), expected_comments_summary) |
Leszek Swirski | 45b20c4 | 2018-09-17 17:05:26 +0000 | [diff] [blame] | 3258 | self.assertEqual(0, git_cl.main(['comment', '--rietveld', '-i', '10', |
| 3259 | '-j', 'output.json'])) |
Andrii Shyshkalov | d8aa49f | 2017-03-17 16:05:49 +0100 | [diff] [blame] | 3260 | |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3261 | def test_git_cl_comments_fetch_gerrit(self): |
| 3262 | self.mock(sys, 'stdout', StringIO.StringIO()) |
| 3263 | self.calls = [ |
| 3264 | ((['git', 'symbolic-ref', 'HEAD'],), CERR1), |
| 3265 | ((['git', 'symbolic-ref', 'HEAD'],), CERR1), |
| 3266 | ((['git', 'config', 'rietveld.upstream-branch'],), CERR1), |
| 3267 | ((['git', 'branch', '-r'],), 'origin/HEAD -> origin/master\n' |
| 3268 | 'origin/master'), |
| 3269 | ((['git', 'config', 'remote.origin.url'],), |
| 3270 | 'https://chromium.googlesource.com/infra/infra'), |
Andrii Shyshkalov | 03e0ed2 | 2018-08-28 19:39:30 +0000 | [diff] [blame] | 3271 | (('GetChangeDetail', 'chromium-review.googlesource.com', |
| 3272 | 'infra%2Finfra~1', |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3273 | ['MESSAGES', 'DETAILED_ACCOUNTS']), { |
Aaron Gable | 0ffdf2d | 2017-06-05 13:01:17 -0700 | [diff] [blame] | 3274 | 'owner': {'email': 'owner@example.com'}, |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3275 | 'messages': [ |
| 3276 | { |
| 3277 | u'_revision_number': 1, |
| 3278 | u'author': { |
| 3279 | u'_account_id': 1111084, |
| 3280 | u'email': u'commit-bot@chromium.org', |
| 3281 | u'name': u'Commit Bot' |
| 3282 | }, |
| 3283 | u'date': u'2017-03-15 20:08:45.000000000', |
| 3284 | u'id': u'f5a6c25ecbd3b3b54a43ae418ed97eff046dc50b', |
Dirk Pranke | f6a5880 | 2017-10-17 12:49:42 -0700 | [diff] [blame] | 3285 | u'message': u'Patch Set 1:\n\nDry run: CQ is trying the patch...', |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3286 | u'tag': u'autogenerated:cq:dry-run' |
| 3287 | }, |
| 3288 | { |
| 3289 | u'_revision_number': 2, |
| 3290 | u'author': { |
| 3291 | u'_account_id': 11151243, |
| 3292 | u'email': u'owner@example.com', |
| 3293 | u'name': u'owner' |
| 3294 | }, |
| 3295 | u'date': u'2017-03-16 20:00:41.000000000', |
| 3296 | u'id': u'f5a6c25ecbd3b3b54a43ae418ed97eff046d1234', |
| 3297 | u'message': u'PTAL', |
| 3298 | }, |
| 3299 | { |
| 3300 | u'_revision_number': 2, |
| 3301 | u'author': { |
| 3302 | u'_account_id': 148512 , |
| 3303 | u'email': u'reviewer@example.com', |
| 3304 | u'name': u'reviewer' |
| 3305 | }, |
| 3306 | u'date': u'2017-03-17 05:19:37.500000000', |
| 3307 | u'id': u'f5a6c25ecbd3b3b54a43ae418ed97eff046d4568', |
| 3308 | u'message': u'Patch Set 2: Code-Review+1', |
| 3309 | }, |
| 3310 | ] |
Aaron Gable | 0ffdf2d | 2017-06-05 13:01:17 -0700 | [diff] [blame] | 3311 | }), |
Andrii Shyshkalov | 889677c | 2018-08-28 20:43:06 +0000 | [diff] [blame] | 3312 | (('GetChangeComments', 'chromium-review.googlesource.com', |
| 3313 | 'infra%2Finfra~1'), { |
Aaron Gable | 0ffdf2d | 2017-06-05 13:01:17 -0700 | [diff] [blame] | 3314 | '/COMMIT_MSG': [ |
| 3315 | { |
| 3316 | 'author': {'email': u'reviewer@example.com'}, |
| 3317 | 'updated': u'2017-03-17 05:19:37.500000000', |
| 3318 | 'patch_set': 2, |
| 3319 | 'side': 'REVISION', |
| 3320 | 'message': 'Please include a bug link', |
| 3321 | }, |
| 3322 | ], |
| 3323 | 'codereview.settings': [ |
| 3324 | { |
| 3325 | 'author': {'email': u'owner@example.com'}, |
| 3326 | 'updated': u'2017-03-16 20:00:41.000000000', |
| 3327 | 'patch_set': 2, |
| 3328 | 'side': 'PARENT', |
| 3329 | 'line': 42, |
| 3330 | 'message': 'I removed this because it is bad', |
| 3331 | }, |
| 3332 | ] |
Leszek Swirski | 45b20c4 | 2018-09-17 17:05:26 +0000 | [diff] [blame] | 3333 | }) |
| 3334 | ] * 2 + [ |
| 3335 | (('write_json', 'output.json', [ |
| 3336 | { |
| 3337 | u'date': u'2017-03-16 20:00:41.000000', |
| 3338 | u'message': ( |
| 3339 | u'PTAL\n' + |
| 3340 | u'\n' + |
| 3341 | u'codereview.settings\n' + |
| 3342 | u' Base, Line 42: https://chromium-review.googlesource.com/' + |
| 3343 | u'c/1/2/codereview.settings#b42\n' + |
| 3344 | u' I removed this because it is bad\n'), |
| 3345 | u'approval': False, |
| 3346 | u'disapproval': False, |
| 3347 | u'sender': u'owner@example.com' |
| 3348 | }, { |
| 3349 | u'date': u'2017-03-17 05:19:37.500000', |
| 3350 | u'message': ( |
| 3351 | u'Patch Set 2: Code-Review+1\n' + |
| 3352 | u'\n' + |
| 3353 | u'/COMMIT_MSG\n' + |
| 3354 | u' PS2, File comment: https://chromium-review.googlesource' + |
| 3355 | u'.com/c/1/2//COMMIT_MSG#\n' + |
| 3356 | u' Please include a bug link\n'), |
| 3357 | u'approval': False, |
| 3358 | u'disapproval': False, |
| 3359 | u'sender': u'reviewer@example.com' |
| 3360 | } |
| 3361 | ]),'') |
| 3362 | ] |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3363 | expected_comments_summary = [ |
| 3364 | git_cl._CommentSummary( |
Aaron Gable | 0ffdf2d | 2017-06-05 13:01:17 -0700 | [diff] [blame] | 3365 | message=( |
| 3366 | u'PTAL\n' + |
| 3367 | u'\n' + |
| 3368 | u'codereview.settings\n' + |
| 3369 | u' Base, Line 42: https://chromium-review.googlesource.com/' + |
| 3370 | u'c/1/2/codereview.settings#b42\n' + |
| 3371 | u' I removed this because it is bad\n'), |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3372 | date=datetime.datetime(2017, 3, 16, 20, 0, 41, 0), |
| 3373 | disapproval=False, approval=False, sender=u'owner@example.com'), |
| 3374 | git_cl._CommentSummary( |
Aaron Gable | 0ffdf2d | 2017-06-05 13:01:17 -0700 | [diff] [blame] | 3375 | message=( |
| 3376 | u'Patch Set 2: Code-Review+1\n' + |
| 3377 | u'\n' + |
| 3378 | u'/COMMIT_MSG\n' + |
| 3379 | u' PS2, File comment: https://chromium-review.googlesource.com/' + |
| 3380 | u'c/1/2//COMMIT_MSG#\n' + |
| 3381 | u' Please include a bug link\n'), |
Andrii Shyshkalov | 5a0cf20 | 2017-03-17 16:14:59 +0100 | [diff] [blame] | 3382 | date=datetime.datetime(2017, 3, 17, 5, 19, 37, 500000), |
| 3383 | disapproval=False, approval=False, sender=u'reviewer@example.com'), |
| 3384 | ] |
| 3385 | cl = git_cl.Changelist(codereview='gerrit', issue=1) |
| 3386 | self.assertEqual(cl.GetCommentsSummary(), expected_comments_summary) |
Leszek Swirski | 45b20c4 | 2018-09-17 17:05:26 +0000 | [diff] [blame] | 3387 | self.assertEqual(0, git_cl.main(['comment', '--gerrit', '-i', '1', |
| 3388 | '-j', 'output.json'])) |
Andrii Shyshkalov | 34924cd | 2017-03-15 17:08:32 +0100 | [diff] [blame] | 3389 | |
Andrii Shyshkalov | 81db1d5 | 2018-08-23 02:17:41 +0000 | [diff] [blame] | 3390 | def test_get_remote_url_with_mirror(self): |
| 3391 | original_os_path_isdir = os.path.isdir |
| 3392 | def selective_os_path_isdir_mock(path): |
| 3393 | if path == '/cache/this-dir-exists': |
| 3394 | return self._mocked_call('os.path.isdir', path) |
| 3395 | return original_os_path_isdir(path) |
| 3396 | self.mock(os.path, 'isdir', selective_os_path_isdir_mock) |
| 3397 | |
| 3398 | url = 'https://chromium.googlesource.com/my/repo' |
| 3399 | self.calls = [ |
| 3400 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 3401 | ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 3402 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 3403 | ((['git', 'config', 'remote.origin.url'],), |
| 3404 | '/cache/this-dir-exists'), |
| 3405 | (('os.path.isdir', '/cache/this-dir-exists'), |
| 3406 | True), |
| 3407 | # Runs in /cache/this-dir-exists. |
| 3408 | ((['git', 'config', 'remote.origin.url'],), |
| 3409 | url), |
| 3410 | ] |
| 3411 | cl = git_cl.Changelist(codereview='gerrit', issue=1) |
| 3412 | self.assertEqual(cl.GetRemoteUrl(), url) |
| 3413 | self.assertEqual(cl.GetRemoteUrl(), url) # Must be cached. |
| 3414 | |
Andrii Shyshkalov | 2d0e03c | 2018-08-25 04:18:09 +0000 | [diff] [blame] | 3415 | def test_gerrit_change_identifier_with_project(self): |
Andrii Shyshkalov | 1e82867 | 2018-08-23 22:34:37 +0000 | [diff] [blame] | 3416 | self.calls = [ |
| 3417 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 3418 | ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 3419 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 3420 | ((['git', 'config', 'remote.origin.url'],), |
| 3421 | 'https://chromium.googlesource.com/a/my/repo.git/'), |
| 3422 | ] |
Andrii Shyshkalov | 2d0e03c | 2018-08-25 04:18:09 +0000 | [diff] [blame] | 3423 | cl = git_cl.Changelist(codereview='gerrit', issue=123456) |
| 3424 | self.assertEqual(cl._GerritChangeIdentifier(), 'my%2Frepo~123456') |
| 3425 | |
| 3426 | def test_gerrit_change_identifier_without_project(self): |
| 3427 | self.calls = [ |
| 3428 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 3429 | ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 3430 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
| 3431 | ((['git', 'config', 'remote.origin.url'],), CERR1), |
| 3432 | ] |
| 3433 | cl = git_cl.Changelist(codereview='gerrit', issue=123456) |
| 3434 | self.assertEqual(cl._GerritChangeIdentifier(), '123456') |
Andrii Shyshkalov | 1e82867 | 2018-08-23 22:34:37 +0000 | [diff] [blame] | 3435 | |
Quinten Yearsley | 0c62da9 | 2017-05-31 13:39:42 -0700 | [diff] [blame] | 3436 | |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 3437 | if __name__ == '__main__': |
Andrii Shyshkalov | 18df0cd | 2017-01-25 15:22:20 +0100 | [diff] [blame] | 3438 | logging.basicConfig( |
| 3439 | level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) |
maruel@chromium.org | ddd5941 | 2011-11-30 14:20:38 +0000 | [diff] [blame] | 3440 | unittest.main() |