[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 1 | #!/usr/bin/env python |
[email protected] | eb5edbc | 2012-01-16 17:03:28 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [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 | |
| 8 | import os |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 9 | import StringIO |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 10 | import stat |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 11 | import sys |
| 12 | import unittest |
| 13 | |
| 14 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| 15 | |
| 16 | from testing_support.auto_stub import TestCase |
| 17 | |
| 18 | import git_cl |
[email protected] | 9e84927 | 2014-04-04 00:31:55 | [diff] [blame] | 19 | import git_common |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 20 | import subprocess2 |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 21 | |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 22 | class PresubmitMock(object): |
| 23 | def __init__(self, *args, **kwargs): |
| 24 | self.reviewers = [] |
| 25 | @staticmethod |
| 26 | def should_continue(): |
| 27 | return True |
| 28 | |
| 29 | |
| 30 | class RietveldMock(object): |
| 31 | def __init__(self, *args, **kwargs): |
| 32 | pass |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 33 | |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 34 | @staticmethod |
| 35 | def get_description(issue): |
| 36 | return 'Issue: %d' % issue |
| 37 | |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 38 | @staticmethod |
| 39 | def get_issue_properties(_issue, _messages): |
| 40 | return { |
| 41 | 'reviewers': ['[email protected]', '[email protected]'], |
| 42 | 'messages': [ |
| 43 | { |
| 44 | 'approval': True, |
| 45 | 'sender': '[email protected]', |
| 46 | }, |
| 47 | ], |
| 48 | } |
| 49 | |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 50 | |
| 51 | class WatchlistsMock(object): |
| 52 | def __init__(self, _): |
| 53 | pass |
| 54 | @staticmethod |
| 55 | def GetWatchersForPaths(_): |
| 56 | return ['[email protected]'] |
| 57 | |
| 58 | |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 59 | class CodereviewSettingsFileMock(object): |
| 60 | def __init__(self): |
| 61 | pass |
| 62 | # pylint: disable=R0201 |
| 63 | def read(self): |
| 64 | return ("CODE_REVIEW_SERVER: gerrit.chromium.org\n" + |
| 65 | "GERRIT_HOST: gerrit.chromium.org\n" + |
| 66 | "GERRIT_PORT: 29418\n") |
| 67 | |
| 68 | |
[email protected] | eed4df3 | 2015-04-10 21:30:20 | [diff] [blame] | 69 | class AuthenticatorMock(object): |
| 70 | def __init__(self, *_args): |
| 71 | pass |
| 72 | def has_cached_credentials(self): |
| 73 | return True |
| 74 | |
| 75 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 76 | class TestGitCl(TestCase): |
| 77 | def setUp(self): |
| 78 | super(TestGitCl, self).setUp() |
| 79 | self.calls = [] |
| 80 | self._calls_done = 0 |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 81 | self.mock(subprocess2, 'call', self._mocked_call) |
| 82 | self.mock(subprocess2, 'check_call', self._mocked_call) |
| 83 | self.mock(subprocess2, 'check_output', self._mocked_call) |
| 84 | self.mock(subprocess2, 'communicate', self._mocked_call) |
[email protected] | 71437c0 | 2015-04-09 19:29:40 | [diff] [blame] | 85 | self.mock(git_common, 'is_dirty_git_tree', lambda x: False) |
[email protected] | 9e84927 | 2014-04-04 00:31:55 | [diff] [blame] | 86 | self.mock(git_common, 'get_or_create_merge_base', |
| 87 | lambda *a: ( |
| 88 | self._mocked_call(['get_or_create_merge_base']+list(a)))) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 89 | self.mock(git_cl, 'FindCodereviewSettingsFile', lambda: '') |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 90 | self.mock(git_cl, 'ask_for_data', self._mocked_call) |
| 91 | self.mock(git_cl.breakpad, 'post', self._mocked_call) |
| 92 | self.mock(git_cl.breakpad, 'SendStack', self._mocked_call) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 93 | self.mock(git_cl.presubmit_support, 'DoPresubmitChecks', PresubmitMock) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 94 | self.mock(git_cl.rietveld, 'Rietveld', RietveldMock) |
[email protected] | 4bac4b5 | 2012-11-27 20:33:52 | [diff] [blame] | 95 | self.mock(git_cl.rietveld, 'CachingRietveld', RietveldMock) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 96 | self.mock(git_cl.upload, 'RealMain', self.fail) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 97 | self.mock(git_cl.watchlists, 'Watchlists', WatchlistsMock) |
[email protected] | eed4df3 | 2015-04-10 21:30:20 | [diff] [blame] | 98 | self.mock(git_cl.auth, 'get_authenticator_for_host', AuthenticatorMock) |
[email protected] | 24daf9e | 2015-04-17 02:42:44 | [diff] [blame^] | 99 | self.mock(git_cl.auth, '_should_use_oauth2', lambda: False) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 100 | # It's important to reset settings to not have inter-tests interference. |
| 101 | git_cl.settings = None |
| 102 | |
| 103 | def tearDown(self): |
| 104 | if not self.has_failed(): |
| 105 | self.assertEquals([], self.calls) |
| 106 | super(TestGitCl, self).tearDown() |
| 107 | |
[email protected] | 9e84927 | 2014-04-04 00:31:55 | [diff] [blame] | 108 | def _mocked_call(self, *args, **_kwargs): |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 109 | self.assertTrue( |
| 110 | self.calls, |
| 111 | '@%d Expected: <Missing> Actual: %r' % (self._calls_done, args)) |
| 112 | expected_args, result = self.calls.pop(0) |
[email protected] | e52678e | 2013-04-26 18:34:44 | [diff] [blame] | 113 | # Also logs otherwise it could get caught in a try/finally and be hard to |
| 114 | # diagnose. |
| 115 | if expected_args != args: |
| 116 | msg = '@%d Expected: %r Actual: %r' % ( |
| 117 | self._calls_done, expected_args, args) |
| 118 | git_cl.logging.error(msg) |
| 119 | self.fail(msg) |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 120 | self._calls_done += 1 |
| 121 | return result |
| 122 | |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 123 | @classmethod |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 124 | def _upload_calls(cls, similarity, find_copies, private): |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 125 | return (cls._git_base_calls(similarity, find_copies) + |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 126 | cls._git_upload_calls(private)) |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 127 | |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 128 | @classmethod |
[email protected] | 615a262 | 2013-05-03 13:20:14 | [diff] [blame] | 129 | def _upload_no_rev_calls(cls, similarity, find_copies): |
| 130 | return (cls._git_base_calls(similarity, find_copies) + |
| 131 | cls._git_upload_no_rev_calls()) |
| 132 | |
| 133 | @classmethod |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 134 | def _git_base_calls(cls, similarity, find_copies): |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 135 | if similarity is None: |
| 136 | similarity = '50' |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 137 | similarity_call = ((['git', 'config', '--int', '--get', |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 138 | 'branch.master.git-cl-similarity'],), '') |
| 139 | else: |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 140 | similarity_call = ((['git', 'config', '--int', |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 141 | 'branch.master.git-cl-similarity', similarity],), '') |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 142 | |
| 143 | if find_copies is None: |
| 144 | find_copies = True |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 145 | find_copies_call = ((['git', 'config', '--int', '--get', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 146 | 'branch.master.git-find-copies'],), '') |
| 147 | else: |
| 148 | val = str(int(find_copies)) |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 149 | find_copies_call = ((['git', 'config', '--int', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 150 | 'branch.master.git-find-copies', val],), '') |
| 151 | |
| 152 | if find_copies: |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 153 | stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 154 | '--find-copies-harder', '-l100000', '-C'+similarity, |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 155 | 'fake_ancestor_sha', 'HEAD'],), '+dat') |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 156 | else: |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 157 | stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 158 | '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 159 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 160 | return [ |
[email protected] | 87884cc | 2014-01-03 22:23:41 | [diff] [blame] | 161 | ((['git', 'config', 'rietveld.autoupdate'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 162 | ((['git', 'config', 'rietveld.server'],), |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 163 | 'codereview.example.com'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 164 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 165 | similarity_call, |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 166 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 167 | find_copies_call, |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 168 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 169 | ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 170 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
[email protected] | 9e84927 | 2014-04-04 00:31:55 | [diff] [blame] | 171 | ((['get_or_create_merge_base', 'master', 'master'],), |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 172 | 'fake_ancestor_sha'), |
[email protected] | eed4df3 | 2015-04-10 21:30:20 | [diff] [blame] | 173 | ((['git', 'config', 'gerrit.host'],), ''), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 174 | ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 175 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 176 | ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 177 | ((['git', 'diff', '--name-status', '--no-renames', '-r', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 178 | 'fake_ancestor_sha...', '.'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 179 | 'M\t.gitignore\n'), |
[email protected] | 5df79ca | 2015-04-13 13:59:24 | [diff] [blame] | 180 | ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 181 | ((['git', 'config', 'branch.master.rietveldpatchset'],), |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 182 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 183 | ((['git', 'log', '--pretty=format:%s%n%n%b', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 184 | 'fake_ancestor_sha...'],), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 185 | 'foo'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 186 | ((['git', 'config', 'user.email'],), '[email protected]'), |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 187 | stat_call, |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 188 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 189 | 'fake_ancestor_sha..HEAD'],), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 190 | 'desc\n'), |
[email protected] | 9075258 | 2014-01-14 21:04:50 | [diff] [blame] | 191 | ((['git', 'config', 'rietveld.bug-prefix'],), ''), |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 192 | ] |
| 193 | |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 194 | @classmethod |
[email protected] | 615a262 | 2013-05-03 13:20:14 | [diff] [blame] | 195 | def _git_upload_no_rev_calls(cls): |
| 196 | return [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 197 | ((['git', 'config', 'core.editor'],), ''), |
[email protected] | 615a262 | 2013-05-03 13:20:14 | [diff] [blame] | 198 | ] |
| 199 | |
| 200 | @classmethod |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 201 | def _git_upload_calls(cls, private): |
| 202 | if private: |
[email protected] | 99918ab | 2013-09-30 06:17:28 | [diff] [blame] | 203 | cc_call = [] |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 204 | private_call = [] |
| 205 | else: |
[email protected] | 99918ab | 2013-09-30 06:17:28 | [diff] [blame] | 206 | cc_call = [((['git', 'config', 'rietveld.cc'],), '')] |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 207 | private_call = [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 208 | ((['git', 'config', 'rietveld.private'],), '')] |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 209 | |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 210 | return [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 211 | ((['git', 'config', 'core.editor'],), ''), |
[email protected] | 99918ab | 2013-09-30 06:17:28 | [diff] [blame] | 212 | ] + cc_call + private_call + [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 213 | ((['git', 'config', 'branch.master.base-url'],), ''), |
[email protected] | 566a02a | 2014-08-22 01:34:13 | [diff] [blame] | 214 | ((['git', 'config', 'rietveld.pending-ref-prefix'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 215 | ((['git', |
[email protected] | 05fb911 | 2014-07-07 09:30:23 | [diff] [blame] | 216 | 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
| 217 | (('', None), 0)), |
[email protected] | 7a54e81 | 2014-02-11 19:57:22 | [diff] [blame] | 218 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 219 | ((['git', 'svn', 'info'],), ''), |
[email protected] | 152cf83 | 2014-06-11 21:37:49 | [diff] [blame] | 220 | ((['git', 'config', 'rietveld.project'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 221 | ((['git', |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 222 | 'config', 'branch.master.rietveldissue', '1'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 223 | ((['git', 'config', 'branch.master.rietveldserver', |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 224 | 'https://codereview.example.com'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 225 | ((['git', |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 226 | 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 227 | ((['git', 'rev-parse', 'HEAD'],), 'hash'), |
| 228 | ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), |
| 229 | ((['git', |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 230 | 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), |
[email protected] | 5626a92 | 2015-02-26 14:03:30 | [diff] [blame] | 231 | ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 232 | ] |
| 233 | |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 234 | @staticmethod |
| 235 | def _git_sanity_checks(diff_base, working_branch): |
| 236 | fake_ancestor = 'fake_ancestor' |
| 237 | fake_cl = 'fake_cl_for_patch' |
| 238 | return [ |
| 239 | # Calls to verify branch point is ancestor |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 240 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 241 | 'rev-parse', '--verify', diff_base],), fake_ancestor), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 242 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 243 | 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 244 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 245 | 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 246 | # Mock a config miss (error code 1) |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 247 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 248 | 'config', 'gitcl.remotebranch'],), (('', None), 1)), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 249 | # Call to GetRemoteBranch() |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 250 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 251 | 'config', 'branch.%s.merge' % working_branch],), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 252 | 'refs/heads/master'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 253 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 254 | 'config', 'branch.%s.remote' % working_branch],), 'origin'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 255 | ((['git', 'rev-list', '^' + fake_ancestor, |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 256 | 'refs/remotes/origin/master'],), ''), |
| 257 | ] |
| 258 | |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 259 | @classmethod |
| 260 | def _dcommit_calls_1(cls): |
| 261 | return [ |
[email protected] | 566a02a | 2014-08-22 01:34:13 | [diff] [blame] | 262 | ((['git', 'config', 'rietveld.autoupdate'],), |
| 263 | ''), |
| 264 | ((['git', 'config', 'rietveld.pending-ref-prefix'],), |
| 265 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 266 | ((['git', |
[email protected] | 05fb911 | 2014-07-07 09:30:23 | [diff] [blame] | 267 | 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 268 | ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' |
| 269 | 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), |
| 270 | None), |
| 271 | 0)), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 272 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 273 | 'config', 'rietveld.server'],), 'codereview.example.com'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 274 | ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 275 | ((['git', 'config', '--int', '--get', |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 276 | 'branch.working.git-cl-similarity'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 277 | ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 278 | ((['git', 'config', '--int', '--get', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 279 | 'branch.working.git-find-copies'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 280 | ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
| 281 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 282 | 'config', 'branch.working.merge'],), 'refs/heads/master'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 283 | ((['git', 'config', 'branch.working.remote'],), 'origin'), |
[email protected] | 5724c96 | 2014-04-11 09:32:56 | [diff] [blame] | 284 | ((['git', 'config', 'branch.working.merge'],), |
| 285 | 'refs/heads/master'), |
| 286 | ((['git', 'config', 'branch.working.remote'],), 'origin'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 287 | ((['git', 'rev-list', '--merges', |
[email protected] | e84b754 | 2012-06-15 21:26:58 | [diff] [blame] | 288 | '--grep=^SVN changes up to revision [0-9]*$', |
[email protected] | 9bb85e2 | 2012-06-13 20:28:23 | [diff] [blame] | 289 | 'refs/remotes/origin/master^!'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 290 | ((['git', 'rev-list', '^refs/heads/working', |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 291 | 'refs/remotes/origin/master'],), |
| 292 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 293 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 294 | 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 295 | '3fc18b62c4966193eb435baabe2d18a3810ec82e'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 296 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 297 | 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 298 | 'refs/remotes/origin/master'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 299 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 300 | 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 301 | 'fake_ancestor_sha'), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 302 | ] |
| 303 | |
| 304 | @classmethod |
| 305 | def _dcommit_calls_normal(cls): |
| 306 | return [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 307 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 308 | ((['git', 'rev-parse', 'HEAD'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 309 | '00ff397798ea57439712ed7e04ab96e13969ef40'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 310 | ((['git', |
[email protected] | 9249f64 | 2013-06-03 21:36:18 | [diff] [blame] | 311 | 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 312 | '.'],), |
| 313 | 'M\tPRESUBMIT.py'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 314 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 315 | 'config', 'branch.working.rietveldissue'],), '12345'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 316 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 317 | 'config', 'branch.working.rietveldpatchset'],), '31137'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 318 | ((['git', 'config', 'branch.working.rietveldserver'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 319 | 'codereview.example.com'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 320 | ((['git', 'config', 'user.email'],), '[email protected]'), |
| 321 | ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 322 | ] |
| 323 | |
| 324 | @classmethod |
| 325 | def _dcommit_calls_bypassed(cls): |
| 326 | return [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 327 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 328 | 'config', 'branch.working.rietveldissue'],), '12345'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 329 | ((['git', 'config', 'branch.working.rietveldserver'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 330 | 'codereview.example.com'), |
[email protected] | 3ec0d54 | 2014-01-14 20:00:03 | [diff] [blame] | 331 | ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 332 | (('GitClHooksBypassedCommit', |
| 333 | 'Issue https://codereview.example.com/12345 bypassed hook when ' |
[email protected] | 3ec0d54 | 2014-01-14 20:00:03 | [diff] [blame] | 334 | 'committing (tree status was "unset")'), None), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 335 | ] |
| 336 | |
| 337 | @classmethod |
[email protected] | 7a54e81 | 2014-02-11 19:57:22 | [diff] [blame] | 338 | def _dcommit_calls_3(cls): |
| 339 | return [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 340 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 341 | 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 342 | '-l100000', '-C50', 'fake_ancestor_sha', |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 343 | 'refs/heads/working'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 344 | (' PRESUBMIT.py | 2 +-\n' |
| 345 | ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 346 | ((['git', 'show-ref', '--quiet', '--verify', |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 347 | 'refs/heads/git-cl-commit'],), |
| 348 | (('', None), 0)), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 349 | ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
| 350 | ((['git', 'show-ref', '--quiet', '--verify', |
[email protected] | 9bb85e2 | 2012-06-13 20:28:23 | [diff] [blame] | 351 | 'refs/heads/git-cl-cherry-pick'],), ''), |
[email protected] | 7a54e81 | 2014-02-11 19:57:22 | [diff] [blame] | 352 | ((['git', 'rev-parse', '--show-cdup'],), '\n'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 353 | ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), |
| 354 | ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), |
| 355 | ((['git', 'commit', '-m', |
[email protected] | e52678e | 2013-04-26 18:34:44 | [diff] [blame] | 356 | 'Issue: 12345\n\[email protected]\n\n' |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 357 | 'Review URL: https://codereview.example.com/12345'],), |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 358 | ''), |
[email protected] | 6abc652 | 2014-12-02 07:34:49 | [diff] [blame] | 359 | ((['git', 'config', 'rietveld.force-https-commit-url'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 360 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 361 | 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 362 | (('', None), 0)), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 363 | ((['git', 'checkout', '-q', 'working'],), ''), |
| 364 | ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
[email protected] | 7a54e81 | 2014-02-11 19:57:22 | [diff] [blame] | 365 | ] |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 366 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 367 | @staticmethod |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 368 | def _cmd_line(description, args, similarity, find_copies, private): |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 369 | """Returns the upload command line passed to upload.RealMain().""" |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 370 | return [ |
| 371 | 'upload', '--assume_yes', '--server', |
[email protected] | eb5edbc | 2012-01-16 17:03:28 | [diff] [blame] | 372 | 'https://codereview.example.com', |
[email protected] | 71e12a9 | 2012-02-14 02:34:15 | [diff] [blame] | 373 | '--message', description |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 374 | ] + args + [ |
| 375 | '--cc', '[email protected]', |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 376 | ] + (['--private'] if private else []) + [ |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 377 | '--git_similarity', similarity or '50' |
| 378 | ] + (['--git_no_find_copies'] if find_copies == False else []) + [ |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 379 | 'fake_ancestor_sha', 'HEAD' |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 380 | ] |
| 381 | |
| 382 | def _run_reviewer_test( |
| 383 | self, |
| 384 | upload_args, |
| 385 | expected_description, |
| 386 | returned_description, |
| 387 | final_description, |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 388 | reviewers, |
| 389 | private=False): |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 390 | """Generic reviewer test framework.""" |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 391 | try: |
| 392 | similarity = upload_args[upload_args.index('--similarity')+1] |
| 393 | except ValueError: |
| 394 | similarity = None |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 395 | |
| 396 | if '--find-copies' in upload_args: |
| 397 | find_copies = True |
| 398 | elif '--no-find-copies' in upload_args: |
| 399 | find_copies = False |
| 400 | else: |
| 401 | find_copies = None |
| 402 | |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 403 | private = '--private' in upload_args |
| 404 | |
| 405 | self.calls = self._upload_calls(similarity, find_copies, private) |
[email protected] | 87884cc | 2014-01-03 22:23:41 | [diff] [blame] | 406 | |
[email protected] | 615a262 | 2013-05-03 13:20:14 | [diff] [blame] | 407 | def RunEditor(desc, _, **kwargs): |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 408 | self.assertEquals( |
| 409 | '# Enter a description of the change.\n' |
[email protected] | 104b2db | 2013-04-18 12:58:40 | [diff] [blame] | 410 | '# This will be displayed on the codereview site.\n' |
[email protected] | 63a4d7f | 2013-05-31 02:22:45 | [diff] [blame] | 411 | '# The first line will also be used as the subject of the review.\n' |
[email protected] | bd1073e | 2013-06-01 00:34:38 | [diff] [blame] | 412 | '#--------------------This line is 72 characters long' |
| 413 | '--------------------\n' + |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 414 | expected_description, |
| 415 | desc) |
| 416 | return returned_description |
| 417 | self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
[email protected] | 87884cc | 2014-01-03 22:23:41 | [diff] [blame] | 418 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 419 | def check_upload(args): |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 420 | cmd_line = self._cmd_line(final_description, reviewers, similarity, |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 421 | find_copies, private) |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 422 | self.assertEquals(cmd_line, args) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 423 | return 1, 2 |
| 424 | self.mock(git_cl.upload, 'RealMain', check_upload) |
[email protected] | 87884cc | 2014-01-03 22:23:41 | [diff] [blame] | 425 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 426 | git_cl.main(['upload'] + upload_args) |
| 427 | |
| 428 | def test_no_reviewer(self): |
| 429 | self._run_reviewer_test( |
| 430 | [], |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 431 | 'desc\n\nBUG=', |
| 432 | '# Blah blah comment.\ndesc\n\nBUG=', |
| 433 | 'desc\n\nBUG=', |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 434 | []) |
| 435 | |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 436 | def test_keep_similarity(self): |
| 437 | self._run_reviewer_test( |
| 438 | ['--similarity', '70'], |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 439 | 'desc\n\nBUG=', |
| 440 | '# Blah blah comment.\ndesc\n\nBUG=', |
| 441 | 'desc\n\nBUG=', |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 442 | []) |
| 443 | |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 444 | def test_keep_find_copies(self): |
| 445 | self._run_reviewer_test( |
| 446 | ['--no-find-copies'], |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 447 | 'desc\n\nBUG=', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 448 | '# Blah blah comment.\ndesc\n\nBUG=\n', |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 449 | 'desc\n\nBUG=', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 450 | []) |
| 451 | |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 452 | def test_private(self): |
| 453 | self._run_reviewer_test( |
| 454 | ['--private'], |
| 455 | 'desc\n\nBUG=', |
| 456 | '# Blah blah comment.\ndesc\n\nBUG=\n', |
| 457 | 'desc\n\nBUG=', |
| 458 | []) |
| 459 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 460 | def test_reviewers_cmd_line(self): |
| 461 | # Reviewer is passed as-is |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 462 | description = 'desc\n\[email protected]\nBUG=' |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 463 | self._run_reviewer_test( |
| 464 | ['-r' '[email protected]'], |
| 465 | description, |
| 466 | '\n%s\n' % description, |
| 467 | description, |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 468 | ['[email protected]']) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 469 | |
| 470 | def test_reviewer_tbr_overriden(self): |
| 471 | # Reviewer is overriden with TBR |
| 472 | # Also verifies the regexp work without a trailing LF |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 473 | description = 'Foo Bar\n\[email protected]' |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 474 | self._run_reviewer_test( |
| 475 | ['-r' '[email protected]'], |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 476 | 'desc\n\[email protected]\nBUG=', |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 477 | description.strip('\n'), |
| 478 | description, |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 479 | ['[email protected]']) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 480 | |
| 481 | def test_reviewer_multiple(self): |
| 482 | # Handles multiple R= or TBR= lines. |
| 483 | description = ( |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 484 | 'Foo Bar\[email protected]\nBUG=\[email protected]') |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 485 | self._run_reviewer_test( |
| 486 | [], |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 487 | 'desc\n\nBUG=', |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 488 | description, |
| 489 | description, |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 490 | ['[email protected],[email protected]']) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 491 | |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 492 | def test_reviewer_send_mail(self): |
| 493 | # --send-mail can be used without -r if R= is used |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 494 | description = 'Foo Bar\[email protected]' |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 495 | self._run_reviewer_test( |
| 496 | ['--send-mail'], |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 497 | 'desc\n\nBUG=', |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 498 | description.strip('\n'), |
| 499 | description, |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 500 | ['[email protected]', '--send_mail']) |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 501 | |
| 502 | def test_reviewer_send_mail_no_rev(self): |
| 503 | # Fails without a reviewer. |
[email protected] | 2e23ce3 | 2013-05-07 12:42:28 | [diff] [blame] | 504 | stdout = StringIO.StringIO() |
| 505 | stderr = StringIO.StringIO() |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 506 | try: |
[email protected] | 615a262 | 2013-05-03 13:20:14 | [diff] [blame] | 507 | self.calls = self._upload_no_rev_calls(None, None) |
| 508 | def RunEditor(desc, _, **kwargs): |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 509 | return desc |
| 510 | self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) |
[email protected] | 2e23ce3 | 2013-05-07 12:42:28 | [diff] [blame] | 511 | self.mock(sys, 'stdout', stdout) |
| 512 | self.mock(sys, 'stderr', stderr) |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 513 | git_cl.main(['upload', '--send-mail']) |
| 514 | self.fail() |
| 515 | except SystemExit: |
[email protected] | 2e23ce3 | 2013-05-07 12:42:28 | [diff] [blame] | 516 | self.assertEqual( |
| 517 | 'Using 50% similarity for rename/copy detection. Override with ' |
| 518 | '--similarity.\n', |
| 519 | stdout.getvalue()) |
| 520 | self.assertEqual( |
| 521 | 'Must specify reviewers to send email.\n', stderr.getvalue()) |
[email protected] | a335365 | 2011-11-30 14:26:57 | [diff] [blame] | 522 | |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 523 | def test_dcommit(self): |
| 524 | self.calls = ( |
| 525 | self._dcommit_calls_1() + |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 526 | self._git_sanity_checks('fake_ancestor_sha', 'working') + |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 527 | self._dcommit_calls_normal() + |
[email protected] | 7a54e81 | 2014-02-11 19:57:22 | [diff] [blame] | 528 | self._dcommit_calls_3()) |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 529 | git_cl.main(['dcommit']) |
| 530 | |
| 531 | def test_dcommit_bypass_hooks(self): |
| 532 | self.calls = ( |
| 533 | self._dcommit_calls_1() + |
| 534 | self._dcommit_calls_bypassed() + |
[email protected] | 7a54e81 | 2014-02-11 19:57:22 | [diff] [blame] | 535 | self._dcommit_calls_3()) |
[email protected] | 2e72bb1 | 2012-01-17 15:18:35 | [diff] [blame] | 536 | git_cl.main(['dcommit', '--bypass-hooks']) |
| 537 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 538 | |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 539 | @classmethod |
| 540 | def _gerrit_base_calls(cls): |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 541 | return [ |
[email protected] | 87884cc | 2014-01-03 22:23:41 | [diff] [blame] | 542 | ((['git', 'config', 'rietveld.autoupdate'],), |
| 543 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 544 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 545 | 'config', 'rietveld.server'],), 'codereview.example.com'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 546 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 547 | ((['git', 'config', '--int', '--get', |
[email protected] | 53937ba | 2012-10-02 18:20:43 | [diff] [blame] | 548 | 'branch.master.git-cl-similarity'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 549 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 550 | ((['git', 'config', '--int', '--get', |
[email protected] | 7954005 | 2012-10-19 23:15:26 | [diff] [blame] | 551 | 'branch.master.git-find-copies'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 552 | ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
| 553 | ((['git', 'config', 'branch.master.merge'],), 'master'), |
| 554 | ((['git', 'config', 'branch.master.remote'],), 'origin'), |
[email protected] | 9e84927 | 2014-04-04 00:31:55 | [diff] [blame] | 555 | ((['get_or_create_merge_base', 'master', 'master'],), |
| 556 | 'fake_ancestor_sha'), |
[email protected] | eed4df3 | 2015-04-10 21:30:20 | [diff] [blame] | 557 | ((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 558 | ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 559 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
| 560 | ((['git', 'rev-parse', 'HEAD'],), '12345'), |
| 561 | ((['git', |
[email protected] | 9249f64 | 2013-06-03 21:36:18 | [diff] [blame] | 562 | 'diff', '--name-status', '--no-renames', '-r', |
| 563 | 'fake_ancestor_sha...', '.'],), |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 564 | 'M\t.gitignore\n'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 565 | ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 566 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 567 | 'config', 'branch.master.rietveldpatchset'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 568 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 569 | 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
[email protected] | 0f58fa8 | 2012-11-05 01:45:20 | [diff] [blame] | 570 | 'foo'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 571 | ((['git', 'config', 'user.email'],), '[email protected]'), |
| 572 | ((['git', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 573 | 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 574 | '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 575 | '+dat'), |
| 576 | ] |
| 577 | |
| 578 | @staticmethod |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 579 | def _gerrit_upload_calls(description, reviewers, squash): |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 580 | calls = [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 581 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 582 | 'fake_ancestor_sha..HEAD'],), |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 583 | description) |
| 584 | ] |
| 585 | if git_cl.CHANGE_ID not in description: |
| 586 | calls += [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 587 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 588 | 'fake_ancestor_sha..HEAD'],), |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 589 | description), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 590 | ((['git', 'commit', '--amend', '-m', description],), |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 591 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 592 | ((['git', 'log', '--pretty=format:%s\n\n%b', |
[email protected] | 5e07e06 | 2013-02-28 23:55:44 | [diff] [blame] | 593 | 'fake_ancestor_sha..HEAD'],), |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 594 | description) |
| 595 | ] |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 596 | if squash: |
| 597 | ref_to_push = 'abcdef0123456789' |
| 598 | calls += [ |
| 599 | ((['git', 'show', '--format=%s\n\n%b', '-s', |
| 600 | 'refs/heads/git_cl_uploads/master'],), |
| 601 | (description, 0)), |
| 602 | ((['git', 'config', 'branch.master.merge'],), |
| 603 | 'refs/heads/master'), |
| 604 | ((['git', 'config', 'branch.master.remote'],), |
| 605 | 'origin'), |
| 606 | ((['get_or_create_merge_base', 'master', 'master'],), |
| 607 | 'origin/master'), |
| 608 | ((['git', 'rev-parse', 'HEAD:'],), |
| 609 | '0123456789abcdef'), |
| 610 | ((['git', 'commit-tree', '0123456789abcdef', '-p', |
| 611 | 'origin/master', '-m', 'd'],), |
| 612 | ref_to_push), |
| 613 | ] |
| 614 | else: |
| 615 | ref_to_push = 'HEAD' |
| 616 | |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 617 | calls += [ |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 618 | ((['git', 'rev-list', 'origin/master..' + ref_to_push],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 619 | ((['git', 'config', 'rietveld.cc'],), '') |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 620 | ] |
[email protected] | 19bbfa2 | 2012-02-03 16:18:11 | [diff] [blame] | 621 | receive_pack = '--receive-pack=git receive-pack ' |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 622 | receive_pack += '[email protected]' # from watch list |
| 623 | if reviewers: |
| 624 | receive_pack += ' ' |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 625 | receive_pack += ' '.join( |
| 626 | '--reviewer=' + email for email in sorted(reviewers)) |
[email protected] | 19bbfa2 | 2012-02-03 16:18:11 | [diff] [blame] | 627 | receive_pack += '' |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 628 | calls += [ |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 629 | ((['git', |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 630 | 'push', receive_pack, 'origin', ref_to_push + ':refs/for/master'],), |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 631 | '') |
| 632 | ] |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 633 | if squash: |
| 634 | calls += [ |
| 635 | ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), |
| 636 | ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', |
| 637 | 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), |
| 638 | '') |
| 639 | ] |
| 640 | |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 641 | return calls |
| 642 | |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 643 | def _run_gerrit_upload_test( |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 644 | self, |
| 645 | upload_args, |
| 646 | description, |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 647 | reviewers, |
| 648 | squash=False): |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 649 | """Generic gerrit upload test framework.""" |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 650 | self.calls = self._gerrit_base_calls() |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 651 | self.calls += self._gerrit_upload_calls(description, reviewers, squash) |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 652 | git_cl.main(['upload'] + upload_args) |
| 653 | |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 654 | def test_gerrit_upload_without_change_id(self): |
| 655 | self._run_gerrit_upload_test( |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 656 | [], |
[email protected] | 35d1a84 | 2012-07-27 00:20:43 | [diff] [blame] | 657 | 'desc\n\nBUG=\n', |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 658 | []) |
| 659 | |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 660 | def test_gerrit_no_reviewer(self): |
| 661 | self._run_gerrit_upload_test( |
| 662 | [], |
| 663 | 'desc\n\nBUG=\nChange-Id:123456789\n', |
| 664 | []) |
| 665 | |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 666 | def test_gerrit_reviewers_cmd_line(self): |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 667 | self._run_gerrit_upload_test( |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 668 | ['-r', '[email protected]'], |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 669 | 'desc\n\nBUG=\nChange-Id:123456789', |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 670 | ['[email protected]']) |
| 671 | |
| 672 | def test_gerrit_reviewer_multiple(self): |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 673 | self._run_gerrit_upload_test( |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 674 | [], |
[email protected] | aebe87f | 2012-10-22 20:34:21 | [diff] [blame] | 675 | 'desc\[email protected]\nBUG=\[email protected]\n' |
| 676 | 'Change-Id:123456789\n', |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 677 | ['[email protected]', '[email protected]']) |
| 678 | |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 679 | def test_gerrit_upload_squash(self): |
| 680 | self._run_gerrit_upload_test( |
| 681 | ['--squash'], |
| 682 | 'desc\n\nBUG=\nChange-Id:123456789\n', |
| 683 | [], |
| 684 | squash=True) |
[email protected] | e807781 | 2012-02-03 03:41:46 | [diff] [blame] | 685 | |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 686 | def test_config_gerrit_download_hook(self): |
| 687 | self.mock(git_cl, 'FindCodereviewSettingsFile', CodereviewSettingsFileMock) |
| 688 | def ParseCodereviewSettingsContent(content): |
| 689 | keyvals = {} |
| 690 | keyvals['CODE_REVIEW_SERVER'] = 'gerrit.chromium.org' |
| 691 | keyvals['GERRIT_HOST'] = 'gerrit.chromium.org' |
| 692 | keyvals['GERRIT_PORT'] = '29418' |
| 693 | return keyvals |
| 694 | self.mock(git_cl.gclient_utils, 'ParseCodereviewSettingsContent', |
| 695 | ParseCodereviewSettingsContent) |
| 696 | self.mock(git_cl.os, 'access', self._mocked_call) |
| 697 | self.mock(git_cl.os, 'chmod', self._mocked_call) |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 698 | src_dir = os.path.join(os.path.sep, 'usr', 'local', 'src') |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 699 | def AbsPath(path): |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 700 | if not path.startswith(os.path.sep): |
| 701 | return os.path.join(src_dir, path) |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 702 | return path |
| 703 | self.mock(git_cl.os.path, 'abspath', AbsPath) |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 704 | commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 705 | def Exists(path): |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 706 | if path == commit_msg_path: |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 707 | return False |
| 708 | # others paths, such as /usr/share/locale/.... |
| 709 | return True |
| 710 | self.mock(git_cl.os.path, 'exists', Exists) |
[email protected] | 426f69b | 2012-08-02 23:41:49 | [diff] [blame] | 711 | self.mock(git_cl, 'urlretrieve', self._mocked_call) |
[email protected] | 712d610 | 2013-11-27 00:52:58 | [diff] [blame] | 712 | self.mock(git_cl, 'hasSheBang', self._mocked_call) |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 713 | self.calls = [ |
[email protected] | 87884cc | 2014-01-03 22:23:41 | [diff] [blame] | 714 | ((['git', 'config', 'rietveld.autoupdate'],), |
| 715 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 716 | ((['git', 'config', 'rietveld.server', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 717 | 'gerrit.chromium.org'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 718 | ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), |
| 719 | ((['git', 'config', '--unset-all', |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 720 | 'rietveld.private'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 721 | ((['git', 'config', '--unset-all', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 722 | 'rietveld.tree-status-url'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 723 | ((['git', 'config', '--unset-all', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 724 | 'rietveld.viewvc-url'],), ''), |
[email protected] | 9075258 | 2014-01-14 21:04:50 | [diff] [blame] | 725 | ((['git', 'config', '--unset-all', |
| 726 | 'rietveld.bug-prefix'],), ''), |
[email protected] | 44202a2 | 2014-03-11 19:22:18 | [diff] [blame] | 727 | ((['git', 'config', '--unset-all', |
| 728 | 'rietveld.cpplint-regex'],), ''), |
| 729 | ((['git', 'config', '--unset-all', |
[email protected] | 6abc652 | 2014-12-02 07:34:49 | [diff] [blame] | 730 | 'rietveld.force-https-commit-url'],), ''), |
| 731 | ((['git', 'config', '--unset-all', |
[email protected] | 44202a2 | 2014-03-11 19:22:18 | [diff] [blame] | 732 | 'rietveld.cpplint-ignore-regex'],), ''), |
[email protected] | 152cf83 | 2014-06-11 21:37:49 | [diff] [blame] | 733 | ((['git', 'config', '--unset-all', |
| 734 | 'rietveld.project'],), ''), |
[email protected] | 566a02a | 2014-08-22 01:34:13 | [diff] [blame] | 735 | ((['git', 'config', '--unset-all', |
| 736 | 'rietveld.pending-ref-prefix'],), ''), |
[email protected] | 5626a92 | 2015-02-26 14:03:30 | [diff] [blame] | 737 | ((['git', 'config', '--unset-all', |
| 738 | 'rietveld.run-post-upload-hook'],), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 739 | ((['git', 'config', 'gerrit.host', |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 740 | 'gerrit.chromium.org'],), ''), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 741 | # DownloadHooks(False) |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 742 | ((['git', 'config', 'gerrit.host'],), |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 743 | 'gerrit.chromium.org'), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 744 | ((['git', 'rev-parse', '--show-cdup'],), ''), |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 745 | ((commit_msg_path, os.X_OK,), False), |
[email protected] | 712d610 | 2013-11-27 00:52:58 | [diff] [blame] | 746 | (('https://gerrit-review.googlesource.com/tools/hooks/commit-msg', |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 747 | commit_msg_path,), ''), |
[email protected] | 712d610 | 2013-11-27 00:52:58 | [diff] [blame] | 748 | ((commit_msg_path,), True), |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 749 | ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 750 | # GetCodereviewSettingsInteractively |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 751 | ((['git', 'config', 'rietveld.server'],), |
[email protected] | f267b0e | 2013-05-02 09:11:43 | [diff] [blame] | 752 | 'gerrit.chromium.org'), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 753 | (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), |
| 754 | ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 755 | ((['git', 'config', 'rietveld.cc'],), ''), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 756 | (('CC list:',), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 757 | ((['git', 'config', 'rietveld.private'],), ''), |
[email protected] | c1737d0 | 2013-05-29 14:17:28 | [diff] [blame] | 758 | (('Private flag (rietveld only):',), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 759 | ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 760 | (('Tree status URL:',), ''), |
[email protected] | 82b91cd | 2013-07-09 06:33:41 | [diff] [blame] | 761 | ((['git', 'config', 'rietveld.viewvc-url'],), ''), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 762 | (('ViewVC URL:',), ''), |
| 763 | # DownloadHooks(True) |
[email protected] | 9075258 | 2014-01-14 21:04:50 | [diff] [blame] | 764 | ((['git', 'config', 'rietveld.bug-prefix'],), ''), |
| 765 | (('Bug Prefix:',), ''), |
[email protected] | 5626a92 | 2015-02-26 14:03:30 | [diff] [blame] | 766 | ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), |
| 767 | (('Run Post Upload Hook:',), ''), |
[email protected] | 9165550 | 2012-05-25 01:46:07 | [diff] [blame] | 768 | ((commit_msg_path, os.X_OK,), True), |
[email protected] | 78c4b98 | 2012-02-14 02:20:26 | [diff] [blame] | 769 | ] |
| 770 | git_cl.main(['config']) |
| 771 | |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 772 | def test_update_reviewers(self): |
| 773 | data = [ |
| 774 | ('foo', [], 'foo'), |
[email protected] | 42c2079 | 2013-09-12 17:34:49 | [diff] [blame] | 775 | ('foo\nR=xx', [], 'foo\nR=xx'), |
| 776 | ('foo\nTBR=xx', [], 'foo\nTBR=xx'), |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 777 | ('foo', ['a@c'], 'foo\n\nR=a@c'), |
[email protected] | 42c2079 | 2013-09-12 17:34:49 | [diff] [blame] | 778 | ('foo\nR=xx', ['a@c'], 'foo\n\nR=a@c, xx'), |
| 779 | ('foo\nTBR=xx', ['a@c'], 'foo\n\nR=a@c\nTBR=xx'), |
| 780 | ('foo\nTBR=xx\nR=yy', ['a@c'], 'foo\n\nR=a@c, yy\nTBR=xx'), |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 781 | ('foo\nBUG=', ['a@c'], 'foo\nBUG=\nR=a@c'), |
[email protected] | 42c2079 | 2013-09-12 17:34:49 | [diff] [blame] | 782 | ('foo\nR=xx\nTBR=yy\nR=bar', ['a@c'], 'foo\n\nR=a@c, xx, bar\nTBR=yy'), |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 783 | ('foo', ['a@c', 'b@c'], 'foo\n\nR=a@c, b@c'), |
[email protected] | c6f60e8 | 2013-04-19 17:01:57 | [diff] [blame] | 784 | ('foo\nBar\n\nR=\nBUG=', ['c@c'], 'foo\nBar\n\nR=c@c\nBUG='), |
| 785 | ('foo\nBar\n\nR=\nBUG=\nR=', ['c@c'], 'foo\nBar\n\nR=c@c\nBUG='), |
| 786 | # Same as the line before, but full of whitespaces. |
| 787 | ( |
| 788 | 'foo\nBar\n\n R = \n BUG = \n R = ', ['c@c'], |
| 789 | 'foo\nBar\n\nR=c@c\n BUG =', |
| 790 | ), |
| 791 | # Whitespaces aren't interpreted as new lines. |
| 792 | ('foo BUG=allo R=joe ', ['c@c'], 'foo BUG=allo R=joe\n\nR=c@c'), |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 793 | ] |
[email protected] | c6f60e8 | 2013-04-19 17:01:57 | [diff] [blame] | 794 | expected = [i[2] for i in data] |
| 795 | actual = [] |
| 796 | for orig, reviewers, _expected in data: |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 797 | obj = git_cl.ChangeDescription(orig) |
| 798 | obj.update_reviewers(reviewers) |
[email protected] | c6f60e8 | 2013-04-19 17:01:57 | [diff] [blame] | 799 | actual.append(obj.description) |
| 800 | self.assertEqual(expected, actual) |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 801 | |
[email protected] | 455dc92 | 2015-01-26 20:15:50 | [diff] [blame] | 802 | def test_get_target_ref(self): |
| 803 | # Check remote or remote branch not present. |
| 804 | self.assertEqual(None, git_cl.GetTargetRef('origin', None, 'master', None)) |
| 805 | self.assertEqual(None, git_cl.GetTargetRef(None, |
| 806 | 'refs/remotes/origin/master', |
| 807 | 'master', None)) |
[email protected] | 27386dd | 2015-02-16 10:45:39 | [diff] [blame] | 808 | |
[email protected] | 455dc92 | 2015-01-26 20:15:50 | [diff] [blame] | 809 | # Check default target refs for branches. |
| 810 | self.assertEqual('refs/heads/master', |
| 811 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', |
| 812 | None, None)) |
| 813 | self.assertEqual('refs/heads/master', |
| 814 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkgr', |
| 815 | None, None)) |
| 816 | self.assertEqual('refs/heads/master', |
| 817 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkcr', |
| 818 | None, None)) |
| 819 | self.assertEqual('refs/branch-heads/123', |
| 820 | git_cl.GetTargetRef('origin', |
| 821 | 'refs/remotes/branch-heads/123', |
| 822 | None, None)) |
| 823 | self.assertEqual('refs/diff/test', |
| 824 | git_cl.GetTargetRef('origin', |
| 825 | 'refs/remotes/origin/refs/diff/test', |
| 826 | None, None)) |
[email protected] | c68112d | 2015-03-03 12:48:06 | [diff] [blame] | 827 | self.assertEqual('refs/heads/chrome/m42', |
| 828 | git_cl.GetTargetRef('origin', |
| 829 | 'refs/remotes/origin/chrome/m42', |
| 830 | None, None)) |
[email protected] | 455dc92 | 2015-01-26 20:15:50 | [diff] [blame] | 831 | |
| 832 | # Check target refs for user-specified target branch. |
| 833 | for branch in ('branch-heads/123', 'remotes/branch-heads/123', |
| 834 | 'refs/remotes/branch-heads/123'): |
| 835 | self.assertEqual('refs/branch-heads/123', |
| 836 | git_cl.GetTargetRef('origin', |
| 837 | 'refs/remotes/origin/master', |
| 838 | branch, None)) |
| 839 | for branch in ('origin/master', 'remotes/origin/master', |
| 840 | 'refs/remotes/origin/master'): |
| 841 | self.assertEqual('refs/heads/master', |
| 842 | git_cl.GetTargetRef('origin', |
| 843 | 'refs/remotes/branch-heads/123', |
| 844 | branch, None)) |
| 845 | for branch in ('master', 'heads/master', 'refs/heads/master'): |
| 846 | self.assertEqual('refs/heads/master', |
| 847 | git_cl.GetTargetRef('origin', |
| 848 | 'refs/remotes/branch-heads/123', |
| 849 | branch, None)) |
| 850 | |
| 851 | # Check target refs for pending prefix. |
| 852 | self.assertEqual('prefix/heads/master', |
| 853 | git_cl.GetTargetRef('origin', 'refs/remotes/origin/master', |
| 854 | None, 'prefix/')) |
| 855 | |
| 856 | |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 857 | if __name__ == '__main__': |
[email protected] | 78936cb | 2013-04-11 00:17:52 | [diff] [blame] | 858 | git_cl.logging.basicConfig( |
| 859 | level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
[email protected] | ddd5941 | 2011-11-30 14:20:38 | [diff] [blame] | 860 | unittest.main() |