Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: tests/git_cl_test.py

Issue 14104005: Fix 236148: Avoid triggering a pager in internal git commands. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Fixed some tests and other calls too. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « scm.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for git_cl.py.""" 6 """Unit tests for git_cl.py."""
7 7
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import stat 10 import stat
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 @classmethod 111 @classmethod
112 def _upload_calls(cls, similarity, find_copies): 112 def _upload_calls(cls, similarity, find_copies):
113 return (cls._git_base_calls(similarity, find_copies) + 113 return (cls._git_base_calls(similarity, find_copies) +
114 cls._git_upload_calls()) 114 cls._git_upload_calls())
115 115
116 @classmethod 116 @classmethod
117 def _git_base_calls(cls, similarity, find_copies): 117 def _git_base_calls(cls, similarity, find_copies):
118 if similarity is None: 118 if similarity is None:
119 similarity = '50' 119 similarity = '50'
120 similarity_call = ((['git', 'config', '--int', '--get', 120 similarity_call = ((['git', '--no-pager', 'config', '--int', '--get',
121 'branch.master.git-cl-similarity'],), '') 121 'branch.master.git-cl-similarity'],), '')
122 else: 122 else:
123 similarity_call = ((['git', 'config', '--int', 123 similarity_call = ((['git', '--no-pager', 'config', '--int',
124 'branch.master.git-cl-similarity', similarity],), '') 124 'branch.master.git-cl-similarity', similarity],), '')
125 125
126 if find_copies is None: 126 if find_copies is None:
127 find_copies = True 127 find_copies = True
128 find_copies_call = ((['git', 'config', '--int', '--get', 128 find_copies_call = ((['git', '--no-pager', 'config', '--int', '--get',
129 'branch.master.git-find-copies'],), '') 129 'branch.master.git-find-copies'],), '')
130 else: 130 else:
131 val = str(int(find_copies)) 131 val = str(int(find_copies))
132 find_copies_call = ((['git', 'config', '--int', 132 find_copies_call = ((['git', '--no-pager', 'config', '--int',
133 'branch.master.git-find-copies', val],), '') 133 'branch.master.git-find-copies', val],), '')
134 134
135 if find_copies: 135 if find_copies:
136 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 136 stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat',
137 '--find-copies-harder', '-l100000', '-C'+similarity, 137 '--find-copies-harder', '-l100000', '-C'+similarity,
138 'fake_ancestor_sha', 'HEAD'],), '+dat') 138 'fake_ancestor_sha', 'HEAD'],), '+dat')
139 else: 139 else:
140 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 140 stat_call = ((['git', '--no-pager', 'diff', '--no-ext-diff', '--stat',
141 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') 141 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
142 142
143 return [ 143 return [
144 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 144 ((['git', '--no-pager', 'config', 'rietveld.server'],),
145 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 145 'codereview.example.com'),
146 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
146 similarity_call, 147 similarity_call,
147 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 148 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
148 find_copies_call, 149 find_copies_call,
149 ((['git', 'update-index', '--refresh', '-q'],), ''), 150 ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''),
150 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), 151 ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''),
151 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 152 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
152 ((['git', 'config', 'branch.master.merge'],), 'master'), 153 ((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'),
153 ((['git', 'config', 'branch.master.remote'],), 'origin'), 154 ((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'),
154 ((['git', 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), 155 ((['git', '--no-pager', 'merge-base', 'master', 'HEAD'],),
156 'fake_ancestor_sha'),
155 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ 157 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
156 ((['git', 'rev-parse', '--show-cdup'],), ''), 158 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
157 ((['git', 'rev-parse', 'HEAD'],), '12345'), 159 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'),
158 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],), 160 ((['git', '--no-pager', 'diff', '--name-status', '-r',
161 'fake_ancestor_sha...', '.'],),
159 'M\t.gitignore\n'), 162 'M\t.gitignore\n'),
160 ((['git', 'config', 'branch.master.rietveldissue'],), ''), 163 ((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''),
161 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''), 164 ((['git', '--no-pager', 'config', 'branch.master.rietveldpatchset'],),
162 ((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 165 ''),
166 ((['git', '--no-pager', 'log', '--pretty=format:%s%n%n%b',
167 'fake_ancestor_sha...'],),
163 'foo'), 168 'foo'),
164 ((['git', 'config', 'user.email'],), 'me@example.com'), 169 ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'),
165 stat_call, 170 stat_call,
166 ((['git', 'config', 'gerrit.host'],), ''), 171 ((['git', '--no-pager', 'config', 'gerrit.host'],), ''),
167 ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],), 172 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
173 'fake_ancestor_sha..HEAD'],),
168 'desc\n'), 174 'desc\n'),
169 ] 175 ]
170 176
171 @classmethod 177 @classmethod
172 def _git_upload_calls(cls): 178 def _git_upload_calls(cls):
173 return [ 179 return [
174 ((['git', 'config', 'rietveld.cc'],), ''), 180 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
175 ((['git', 'config', 'branch.master.base-url'],), ''), 181 ((['git', '--no-pager', 'config', 'branch.master.base-url'],), ''),
176 ((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 182 ((['git', '--no-pager',
183 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
177 (('', None), 0)), 184 (('', None), 0)),
178 ((['git', 'rev-parse', '--show-cdup'],), ''), 185 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
179 ((['git', 'svn', 'info'],), ''), 186 ((['git', '--no-pager', 'svn', 'info'],), ''),
180 ((['git', 'config', 'branch.master.rietveldissue', '1'],), ''), 187 ((['git', '--no-pager',
181 ((['git', 'config', 'branch.master.rietveldserver', 188 'config', 'branch.master.rietveldissue', '1'],), ''),
189 ((['git', '--no-pager', 'config', 'branch.master.rietveldserver',
182 'https://codereview.example.com'],), ''), 190 'https://codereview.example.com'],), ''),
183 ((['git', 'config', 'branch.master.rietveldpatchset', '2'],), ''), 191 ((['git', '--no-pager',
184 ((['git', 'rev-parse', 'HEAD'],), 'hash'), 192 'config', 'branch.master.rietveldpatchset', '2'],), ''),
185 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), 193 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), 'hash'),
186 ((['git', 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), 194 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'hash'),
195 ((['git', '--no-pager',
196 'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
187 ] 197 ]
188 198
189 @staticmethod 199 @staticmethod
190 def _git_sanity_checks(diff_base, working_branch): 200 def _git_sanity_checks(diff_base, working_branch):
191 fake_ancestor = 'fake_ancestor' 201 fake_ancestor = 'fake_ancestor'
192 fake_cl = 'fake_cl_for_patch' 202 fake_cl = 'fake_cl_for_patch'
193 return [ 203 return [
194 # Calls to verify branch point is ancestor 204 # Calls to verify branch point is ancestor
195 ((['git', 'rev-parse', '--verify', diff_base],), fake_ancestor), 205 ((['git', '--no-pager',
196 ((['git', 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), 206 'rev-parse', '--verify', diff_base],), fake_ancestor),
197 ((['git', 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), 207 ((['git', '--no-pager',
208 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor),
209 ((['git', '--no-pager',
210 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl),
198 # Mock a config miss (error code 1) 211 # Mock a config miss (error code 1)
199 ((['git', 'config', 'gitcl.remotebranch'],), (('', None), 1)), 212 ((['git', '--no-pager',
213 'config', 'gitcl.remotebranch'],), (('', None), 1)),
200 # Call to GetRemoteBranch() 214 # Call to GetRemoteBranch()
201 ((['git', 'config', 'branch.%s.merge' % working_branch],), 215 ((['git', '--no-pager',
216 'config', 'branch.%s.merge' % working_branch],),
202 'refs/heads/master'), 217 'refs/heads/master'),
203 ((['git', 'config', 'branch.%s.remote' % working_branch],), 'origin'), 218 ((['git', '--no-pager',
204 ((['git', 'rev-list', '^' + fake_ancestor, 219 'config', 'branch.%s.remote' % working_branch],), 'origin'),
220 ((['git', '--no-pager', 'rev-list', '^' + fake_ancestor,
205 'refs/remotes/origin/master'],), ''), 221 'refs/remotes/origin/master'],), ''),
206 ] 222 ]
207 223
208 @classmethod 224 @classmethod
209 def _dcommit_calls_1(cls): 225 def _dcommit_calls_1(cls):
210 return [ 226 return [
211 ((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 227 ((['git', '--no-pager',
228 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
212 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' 229 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n'
213 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), 230 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'),
214 None), 231 None),
215 0)), 232 0)),
216 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 233 ((['git', '--no-pager',
217 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 234 'config', 'rietveld.server'],), 'codereview.example.com'),
218 ((['git', 'config', '--int', '--get', 235 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
236 ((['git', '--no-pager', 'config', '--int', '--get',
219 'branch.working.git-cl-similarity'],), ''), 237 'branch.working.git-cl-similarity'],), ''),
220 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 238 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
221 ((['git', 'config', '--int', '--get', 239 ((['git', '--no-pager', 'config', '--int', '--get',
222 'branch.working.git-find-copies'],), ''), 240 'branch.working.git-find-copies'],), ''),
223 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 241 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
224 ((['git', 'config', 'branch.working.merge'],), 'refs/heads/master'), 242 ((['git', '--no-pager',
225 ((['git', 'config', 'branch.working.remote'],), 'origin'), 243 'config', 'branch.working.merge'],), 'refs/heads/master'),
226 ((['git', 'rev-list', '--merges', 244 ((['git', '--no-pager', 'config', 'branch.working.remote'],), 'origin'),
245 ((['git', '--no-pager', 'rev-list', '--merges',
227 '--grep=^SVN changes up to revision [0-9]*$', 246 '--grep=^SVN changes up to revision [0-9]*$',
228 'refs/remotes/origin/master^!'],), ''), 247 'refs/remotes/origin/master^!'],), ''),
229 ((['git', 'update-index', '--refresh', '-q'],), ''), 248 ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''),
230 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), 249 ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''),
231 ((['git', 'rev-list', '^refs/heads/working', 250 ((['git', '--no-pager', 'rev-list', '^refs/heads/working',
232 'refs/remotes/origin/master'],), 251 'refs/remotes/origin/master'],),
233 ''), 252 ''),
234 ((['git', 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), 253 ((['git', '--no-pager',
254 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],),
235 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), 255 '3fc18b62c4966193eb435baabe2d18a3810ec82e'),
236 ((['git', 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', 256 ((['git', '--no-pager',
257 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e',
237 'refs/remotes/origin/master'],), ''), 258 'refs/remotes/origin/master'],), ''),
238 ((['git', 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), 259 ((['git', '--no-pager',
260 'merge-base', 'refs/remotes/origin/master', 'HEAD'],),
239 'fake_ancestor_sha'), 261 'fake_ancestor_sha'),
240 ] 262 ]
241 263
242 @classmethod 264 @classmethod
243 def _dcommit_calls_normal(cls): 265 def _dcommit_calls_normal(cls):
244 return [ 266 return [
245 ((['git', 'rev-parse', '--show-cdup'],), ''), 267 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
246 ((['git', 'rev-parse', 'HEAD'],), 268 ((['git', '--no-pager', 'rev-parse', 'HEAD'],),
247 '00ff397798ea57439712ed7e04ab96e13969ef40'), 269 '00ff397798ea57439712ed7e04ab96e13969ef40'),
248 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', 270 ((['git', '--no-pager',
271 'diff', '--name-status', '-r', 'fake_ancestor_sha...',
249 '.'],), 272 '.'],),
250 'M\tPRESUBMIT.py'), 273 'M\tPRESUBMIT.py'),
251 ((['git', 'config', 'branch.working.rietveldissue'],), '12345'), 274 ((['git', '--no-pager',
252 ((['git', 'config', 'branch.working.rietveldpatchset'],), '31137'), 275 'config', 'branch.working.rietveldissue'],), '12345'),
253 ((['git', 'config', 'branch.working.rietveldserver'],), 276 ((['git', '--no-pager',
277 'config', 'branch.working.rietveldpatchset'],), '31137'),
278 ((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],),
254 'codereview.example.com'), 279 'codereview.example.com'),
255 ((['git', 'config', 'user.email'],), 'author@example.com'), 280 ((['git', '--no-pager', 'config', 'user.email'],), 'author@example.com'),
256 ((['git', 'config', 'rietveld.tree-status-url'],), ''), 281 ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''),
257 ] 282 ]
258 283
259 @classmethod 284 @classmethod
260 def _dcommit_calls_bypassed(cls): 285 def _dcommit_calls_bypassed(cls):
261 return [ 286 return [
262 ((['git', 'config', 'branch.working.rietveldissue'],), '12345'), 287 ((['git', '--no-pager',
263 ((['git', 'config', 'branch.working.rietveldserver'],), 288 'config', 'branch.working.rietveldissue'],), '12345'),
289 ((['git', '--no-pager', 'config', 'branch.working.rietveldserver'],),
264 'codereview.example.com'), 290 'codereview.example.com'),
265 (('GitClHooksBypassedCommit', 291 (('GitClHooksBypassedCommit',
266 'Issue https://codereview.example.com/12345 bypassed hook when ' 292 'Issue https://codereview.example.com/12345 bypassed hook when '
267 'committing'), None), 293 'committing'), None),
268 ] 294 ]
269 295
270 @classmethod 296 @classmethod
271 def _dcommit_calls_3(cls): 297 def _dcommit_calls_3(cls):
272 return [ 298 return [
273 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 299 ((['git', '--no-pager',
300 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
274 '-l100000', '-C50', 'fake_ancestor_sha', 301 '-l100000', '-C50', 'fake_ancestor_sha',
275 'refs/heads/working'],), 302 'refs/heads/working'],),
276 (' PRESUBMIT.py | 2 +-\n' 303 (' PRESUBMIT.py | 2 +-\n'
277 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), 304 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')),
278 (('About to commit; enter to confirm.',), None), 305 (('About to commit; enter to confirm.',), None),
279 ((['git', 'show-ref', '--quiet', '--verify', 306 ((['git', '--no-pager', 'show-ref', '--quiet', '--verify',
280 'refs/heads/git-cl-commit'],), 307 'refs/heads/git-cl-commit'],),
281 (('', None), 0)), 308 (('', None), 0)),
282 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), 309 ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''),
283 ((['git', 'show-ref', '--quiet', '--verify', 310 ((['git', '--no-pager', 'show-ref', '--quiet', '--verify',
284 'refs/heads/git-cl-cherry-pick'],), ''), 311 'refs/heads/git-cl-cherry-pick'],), ''),
285 ((['git', 'rev-parse', '--show-cdup'],), '\n'), 312 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), '\n'),
286 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), 313 ((['git', '--no-pager', 'checkout', '-q', '-b', 'git-cl-commit'],), ''),
287 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), 314 ((['git', '--no-pager', 'reset', '--soft', 'fake_ancestor_sha'],), ''),
288 ((['git', 'commit', '-m', 315 ((['git', '--no-pager', 'commit', '-m',
289 'Issue: 12345\n\nR=john@chromium.org\n\n' 316 'Issue: 12345\n\nR=john@chromium.org\n\n'
290 'Review URL: https://codereview.example.com/12345'],), 317 'Review URL: https://codereview.example.com/12345'],),
291 ''), 318 ''),
292 ((['git', 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), 319 ((['git', '--no-pager',
320 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],),
293 (('', None), 0)), 321 (('', None), 0)),
294 ((['git', 'checkout', '-q', 'working'],), ''), 322 ((['git', '--no-pager', 'checkout', '-q', 'working'],), ''),
295 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), 323 ((['git', '--no-pager', 'branch', '-D', 'git-cl-commit'],), ''),
296 ] 324 ]
297 325
298 @staticmethod 326 @staticmethod
299 def _cmd_line(description, args, similarity, find_copies): 327 def _cmd_line(description, args, similarity, find_copies):
300 """Returns the upload command line passed to upload.RealMain().""" 328 """Returns the upload command line passed to upload.RealMain()."""
301 return [ 329 return [
302 'upload', '--assume_yes', '--server', 330 'upload', '--assume_yes', '--server',
303 'https://codereview.example.com', 331 'https://codereview.example.com',
304 '--message', description 332 '--message', description
305 ] + args + [ 333 ] + args + [
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 self.calls = ( 473 self.calls = (
446 self._dcommit_calls_1() + 474 self._dcommit_calls_1() +
447 self._dcommit_calls_bypassed() + 475 self._dcommit_calls_bypassed() +
448 self._dcommit_calls_3()) 476 self._dcommit_calls_3())
449 git_cl.main(['dcommit', '--bypass-hooks']) 477 git_cl.main(['dcommit', '--bypass-hooks'])
450 478
451 479
452 @classmethod 480 @classmethod
453 def _gerrit_base_calls(cls): 481 def _gerrit_base_calls(cls):
454 return [ 482 return [
455 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 483 ((['git', '--no-pager',
456 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 484 'config', 'rietveld.server'],), 'codereview.example.com'),
457 ((['git', 'config', '--int', '--get', 485 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
486 ((['git', '--no-pager', 'config', '--int', '--get',
458 'branch.master.git-cl-similarity'],), ''), 487 'branch.master.git-cl-similarity'],), ''),
459 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 488 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
460 ((['git', 'config', '--int', '--get', 489 ((['git', '--no-pager', 'config', '--int', '--get',
461 'branch.master.git-find-copies'],), ''), 490 'branch.master.git-find-copies'],), ''),
462 ((['git', 'update-index', '--refresh', '-q'],), ''), 491 ((['git', '--no-pager', 'update-index', '--refresh', '-q'],), ''),
463 ((['git', 'diff-index', '--name-status', 'HEAD'],), ''), 492 ((['git', '--no-pager', 'diff-index', '--name-status', 'HEAD'],), ''),
464 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 493 ((['git', '--no-pager', 'symbolic-ref', 'HEAD'],), 'master'),
465 ((['git', 'config', 'branch.master.merge'],), 'master'), 494 ((['git', '--no-pager', 'config', 'branch.master.merge'],), 'master'),
466 ((['git', 'config', 'branch.master.remote'],), 'origin'), 495 ((['git', '--no-pager', 'config', 'branch.master.remote'],), 'origin'),
467 ((['git', 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'), 496 ((['git', '--no-pager',
497 'merge-base', 'master', 'HEAD'],), 'fake_ancestor_sha'),
468 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ 498 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
469 ((['git', 'rev-parse', '--show-cdup'],), ''), 499 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
470 ((['git', 'rev-parse', 'HEAD'],), '12345'), 500 ((['git', '--no-pager', 'rev-parse', 'HEAD'],), '12345'),
471 ((['git', 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],), 501 ((['git', '--no-pager',
502 'diff', '--name-status', '-r', 'fake_ancestor_sha...', '.'],),
472 'M\t.gitignore\n'), 503 'M\t.gitignore\n'),
473 ((['git', 'config', 'branch.master.rietveldissue'],), ''), 504 ((['git', '--no-pager', 'config', 'branch.master.rietveldissue'],), ''),
474 ((['git', 'config', 'branch.master.rietveldpatchset'],), ''), 505 ((['git', '--no-pager',
475 ((['git', 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 506 'config', 'branch.master.rietveldpatchset'],), ''),
507 ((['git', '--no-pager',
508 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
476 'foo'), 509 'foo'),
477 ((['git', 'config', 'user.email'],), 'me@example.com'), 510 ((['git', '--no-pager', 'config', 'user.email'],), 'me@example.com'),
478 ((['git', 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 511 ((['git', '--no-pager',
512 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
479 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), 513 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
480 '+dat'), 514 '+dat'),
481 ] 515 ]
482 516
483 @staticmethod 517 @staticmethod
484 def _gerrit_upload_calls(description, reviewers): 518 def _gerrit_upload_calls(description, reviewers):
485 calls = [ 519 calls = [
486 ((['git', 'config', 'gerrit.host'],), 'gerrit.example.com'), 520 ((['git', '--no-pager', 'config', 'gerrit.host'],),
487 ((['git', 'log', '--pretty=format:%s\n\n%b', 521 'gerrit.example.com'),
522 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
488 'fake_ancestor_sha..HEAD'],), 523 'fake_ancestor_sha..HEAD'],),
489 description) 524 description)
490 ] 525 ]
491 if git_cl.CHANGE_ID not in description: 526 if git_cl.CHANGE_ID not in description:
492 calls += [ 527 calls += [
493 ((['git', 'log', '--pretty=format:%s\n\n%b', 528 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
494 'fake_ancestor_sha..HEAD'],), 529 'fake_ancestor_sha..HEAD'],),
495 description), 530 description),
496 ((['git', 'commit', '--amend', '-m', description],), 531 ((['git', '--no-pager', 'commit', '--amend', '-m', description],),
497 ''), 532 ''),
498 ((['git', 'log', '--pretty=format:%s\n\n%b', 533 ((['git', '--no-pager', 'log', '--pretty=format:%s\n\n%b',
499 'fake_ancestor_sha..HEAD'],), 534 'fake_ancestor_sha..HEAD'],),
500 description) 535 description)
501 ] 536 ]
502 calls += [ 537 calls += [
503 ((['git', 'config', 'rietveld.cc'],), '') 538 ((['git', '--no-pager', 'config', 'rietveld.cc'],), '')
504 ] 539 ]
505 receive_pack = '--receive-pack=git receive-pack ' 540 receive_pack = '--receive-pack=git receive-pack '
506 receive_pack += '--cc=joe@example.com' # from watch list 541 receive_pack += '--cc=joe@example.com' # from watch list
507 if reviewers: 542 if reviewers:
508 receive_pack += ' ' 543 receive_pack += ' '
509 receive_pack += ' '.join( 544 receive_pack += ' '.join(
510 '--reviewer=' + email for email in sorted(reviewers)) 545 '--reviewer=' + email for email in sorted(reviewers))
511 receive_pack += '' 546 receive_pack += ''
512 calls += [ 547 calls += [
513 ((['git', 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],), 548 ((['git', '--no-pager',
549 'push', receive_pack, 'origin', 'HEAD:refs/for/master'],),
514 '') 550 '')
515 ] 551 ]
516 return calls 552 return calls
517 553
518 def _run_gerrit_upload_test( 554 def _run_gerrit_upload_test(
519 self, 555 self,
520 upload_args, 556 upload_args,
521 description, 557 description,
522 reviewers): 558 reviewers):
523 """Generic gerrit upload test framework.""" 559 """Generic gerrit upload test framework."""
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 self.mock(git_cl.os.path, 'abspath', AbsPath) 607 self.mock(git_cl.os.path, 'abspath', AbsPath)
572 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg') 608 commit_msg_path = os.path.join(src_dir, '.git', 'hooks', 'commit-msg')
573 def Exists(path): 609 def Exists(path):
574 if path == commit_msg_path: 610 if path == commit_msg_path:
575 return False 611 return False
576 # others paths, such as /usr/share/locale/.... 612 # others paths, such as /usr/share/locale/....
577 return True 613 return True
578 self.mock(git_cl.os.path, 'exists', Exists) 614 self.mock(git_cl.os.path, 'exists', Exists)
579 self.mock(git_cl, 'urlretrieve', self._mocked_call) 615 self.mock(git_cl, 'urlretrieve', self._mocked_call)
580 self.calls = [ 616 self.calls = [
581 ((['git', 'config', 'rietveld.server', 'gerrit.chromium.org'],), ''), 617 ((['git', '--no-pager', 'config', 'rietveld.server',
582 ((['git', 'config', '--unset-all', 'rietveld.cc'],), ''), 618 'gerrit.chromium.org'],), ''),
583 ((['git', 'config', '--unset-all', 'rietveld.tree-status-url'],), ''), 619 ((['git', '--no-pager', 'config', '--unset-all', 'rietveld.cc'],), ''),
584 ((['git', 'config', '--unset-all', 'rietveld.viewvc-url'],), ''), 620 ((['git', '--no-pager', 'config', '--unset-all',
585 ((['git', 'config', 'gerrit.host', 'gerrit.chromium.org'],), ''), 621 'rietveld.tree-status-url'],), ''),
586 ((['git', 'config', 'gerrit.port', '29418'],), ''), 622 ((['git', '--no-pager', 'config', '--unset-all',
623 'rietveld.viewvc-url'],), ''),
624 ((['git', '--no-pager', 'config', 'gerrit.host',
625 'gerrit.chromium.org'],), ''),
626 ((['git', '--no-pager', 'config', 'gerrit.port', '29418'],), ''),
587 # DownloadHooks(False) 627 # DownloadHooks(False)
588 ((['git', 'config', 'gerrit.host'],), 'gerrit.chromium.org'), 628 ((['git', '--no-pager', 'config', 'gerrit.host'],),
589 ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), 629 'gerrit.chromium.org'),
590 ((['git', 'rev-parse', '--show-cdup'],), ''), 630 ((['git', '--no-pager', 'config', 'rietveld.server'],),
631 'gerrit.chromium.org'),
632 ((['git', '--no-pager', 'rev-parse', '--show-cdup'],), ''),
591 ((commit_msg_path, os.X_OK,), False), 633 ((commit_msg_path, os.X_OK,), False),
592 (('https://gerrit.chromium.org/tools/hooks/commit-msg', 634 (('https://gerrit.chromium.org/tools/hooks/commit-msg',
593 commit_msg_path,), ''), 635 commit_msg_path,), ''),
594 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''), 636 ((commit_msg_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR,), ''),
595 # GetCodereviewSettingsInteractively 637 # GetCodereviewSettingsInteractively
596 ((['git', 'config', 'rietveld.server'],), 'gerrit.chromium.org'), 638 ((['git', '--no-pager', 'config', 'rietveld.server'],),
639 'gerrit.chromium.org'),
597 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',), 640 (('Rietveld server (host[:port]) [https://gerrit.chromium.org]:',),
598 ''), 641 ''),
599 ((['git', 'config', 'rietveld.cc'],), ''), 642 ((['git', '--no-pager', 'config', 'rietveld.cc'],), ''),
600 (('CC list:',), ''), 643 (('CC list:',), ''),
601 ((['git', 'config', 'rietveld.tree-status-url'],), ''), 644 ((['git', '--no-pager', 'config', 'rietveld.tree-status-url'],), ''),
602 (('Tree status URL:',), ''), 645 (('Tree status URL:',), ''),
603 ((['git', 'config', 'rietveld.viewvc-url'],), ''), 646 ((['git', '--no-pager', 'config', 'rietveld.viewvc-url'],), ''),
604 (('ViewVC URL:',), ''), 647 (('ViewVC URL:',), ''),
605 # DownloadHooks(True) 648 # DownloadHooks(True)
606 ((commit_msg_path, os.X_OK,), True), 649 ((commit_msg_path, os.X_OK,), True),
607 ] 650 ]
608 git_cl.main(['config']) 651 git_cl.main(['config'])
609 652
610 def test_update_reviewers(self): 653 def test_update_reviewers(self):
611 data = [ 654 data = [
612 ('foo', [], 'foo'), 655 ('foo', [], 'foo'),
613 ('foo', ['a@c'], 'foo\n\nR=a@c'), 656 ('foo', ['a@c'], 'foo\n\nR=a@c'),
(...skipping 16 matching lines...) Expand all
630 obj = git_cl.ChangeDescription(orig) 673 obj = git_cl.ChangeDescription(orig)
631 obj.update_reviewers(reviewers) 674 obj.update_reviewers(reviewers)
632 actual.append(obj.description) 675 actual.append(obj.description)
633 self.assertEqual(expected, actual) 676 self.assertEqual(expected, actual)
634 677
635 678
636 if __name__ == '__main__': 679 if __name__ == '__main__':
637 git_cl.logging.basicConfig( 680 git_cl.logging.basicConfig(
638 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 681 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
639 unittest.main() 682 unittest.main()
OLDNEW
« no previous file with comments | « scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698