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

Side by Side Diff: tests/git_cl_test.py

Issue 2272613002: git cl: workaround against integer overflows of git config. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 4 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 | « git_cl.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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 323
324 @classmethod 324 @classmethod
325 def _upload_no_rev_calls(cls, similarity, find_copies): 325 def _upload_no_rev_calls(cls, similarity, find_copies):
326 return (cls._git_base_calls(similarity, find_copies) + 326 return (cls._git_base_calls(similarity, find_copies) +
327 cls._git_upload_no_rev_calls()) 327 cls._git_upload_no_rev_calls())
328 328
329 @classmethod 329 @classmethod
330 def _git_base_calls(cls, similarity, find_copies): 330 def _git_base_calls(cls, similarity, find_copies):
331 if similarity is None: 331 if similarity is None:
332 similarity = '50' 332 similarity = '50'
333 similarity_call = ((['git', 'config', '--int', 333 similarity_call = ((['git', 'config',
334 'branch.master.git-cl-similarity'],), CERR1) 334 'branch.master.git-cl-similarity'],), CERR1)
335 else: 335 else:
336 similarity_call = ((['git', 'config', '--int', 336 similarity_call = ((['git', 'config',
337 'branch.master.git-cl-similarity', similarity],), '') 337 'branch.master.git-cl-similarity', similarity],), '')
338 338
339 if find_copies is None: 339 if find_copies is None:
340 find_copies = True 340 find_copies = True
341 find_copies_call = ((['git', 'config', '--bool', 341 find_copies_call = ((['git', 'config', '--bool',
342 'branch.master.git-find-copies'],), CERR1) 342 'branch.master.git-find-copies'],), CERR1)
343 else: 343 else:
344 val = str(find_copies).lower() 344 val = str(find_copies).lower()
345 find_copies_call = ((['git', 'config', '--bool', 345 find_copies_call = ((['git', 'config', '--bool',
346 'branch.master.git-find-copies', val],), '') 346 'branch.master.git-find-copies', val],), '')
347 347
348 if find_copies: 348 if find_copies:
349 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 349 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
350 '--find-copies-harder', '-l100000', '-C'+similarity, 350 '--find-copies-harder', '-l100000', '-C'+similarity,
351 'fake_ancestor_sha', 'HEAD'],), '+dat') 351 'fake_ancestor_sha', 'HEAD'],), '+dat')
352 else: 352 else:
353 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', 353 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat',
354 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') 354 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat')
355 355
356 return [ 356 return [
357 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 357 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
358 similarity_call, 358 similarity_call,
359 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 359 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
360 find_copies_call, 360 find_copies_call,
361 ] + cls._is_gerrit_calls() + [ 361 ] + cls._is_gerrit_calls() + [
362 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 362 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
363 ((['git', 'config', '--int', 'branch.master.rietveldissue'],), CERR1), 363 ((['git', 'config', 'branch.master.rietveldissue'],), CERR1),
364 ((['git', 'config', '--int', 'branch.master.gerritissue'],), CERR1), 364 ((['git', 'config', 'branch.master.gerritissue'],), CERR1),
365 ((['git', 'config', 'rietveld.server'],), 365 ((['git', 'config', 'rietveld.server'],),
366 'codereview.example.com'), 366 'codereview.example.com'),
367 ((['git', 'config', 'branch.master.merge'],), 'master'), 367 ((['git', 'config', 'branch.master.merge'],), 'master'),
368 ((['git', 'config', 'branch.master.remote'],), 'origin'), 368 ((['git', 'config', 'branch.master.remote'],), 'origin'),
369 ((['get_or_create_merge_base', 'master', 'master'],), 369 ((['get_or_create_merge_base', 'master', 'master'],),
370 'fake_ancestor_sha'), 370 'fake_ancestor_sha'),
371 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ 371 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
372 ((['git', 'rev-parse', '--show-cdup'],), ''), 372 ((['git', 'rev-parse', '--show-cdup'],), ''),
373 ((['git', 'rev-parse', 'HEAD'],), '12345'), 373 ((['git', 'rev-parse', 'HEAD'],), '12345'),
374 ((['git', 'diff', '--name-status', '--no-renames', '-r', 374 ((['git', 'diff', '--name-status', '--no-renames', '-r',
375 'fake_ancestor_sha...', '.'],), 375 'fake_ancestor_sha...', '.'],),
376 'M\t.gitignore\n'), 376 'M\t.gitignore\n'),
377 ((['git', 'config', '--int', 'branch.master.rietveldpatchset'],), CERR1), 377 ((['git', 'config', 'branch.master.rietveldpatchset'],), CERR1),
378 ((['git', 'log', '--pretty=format:%s%n%n%b', 378 ((['git', 'log', '--pretty=format:%s%n%n%b',
379 'fake_ancestor_sha...'],), 379 'fake_ancestor_sha...'],),
380 'foo'), 380 'foo'),
381 ((['git', 'config', 'user.email'],), 'me@example.com'), 381 ((['git', 'config', 'user.email'],), 'me@example.com'),
382 stat_call, 382 stat_call,
383 ((['git', 'log', '--pretty=format:%s\n\n%b', 383 ((['git', 'log', '--pretty=format:%s\n\n%b',
384 'fake_ancestor_sha..HEAD'],), 384 'fake_ancestor_sha..HEAD'],),
385 'desc\n'), 385 'desc\n'),
386 ((['git', 'config', 'rietveld.bug-prefix'],), ''), 386 ((['git', 'config', 'rietveld.bug-prefix'],), ''),
387 ] 387 ]
(...skipping 18 matching lines...) Expand all
406 ((['git', 'config', 'core.editor'],), ''), 406 ((['git', 'config', 'core.editor'],), ''),
407 ] + cc_call + private_call + [ 407 ] + cc_call + private_call + [
408 ((['git', 'config', 'branch.master.base-url'],), ''), 408 ((['git', 'config', 'branch.master.base-url'],), ''),
409 ((['git', 'config', 'rietveld.pending-ref-prefix'],), ''), 409 ((['git', 'config', 'rietveld.pending-ref-prefix'],), ''),
410 ((['git', 410 ((['git',
411 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 411 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
412 (('', None), 0)), 412 (('', None), 0)),
413 ((['git', 'rev-parse', '--show-cdup'],), ''), 413 ((['git', 'rev-parse', '--show-cdup'],), ''),
414 ((['git', 'svn', 'info'],), ''), 414 ((['git', 'svn', 'info'],), ''),
415 ((['git', 'config', 'rietveld.project'],), ''), 415 ((['git', 'config', 'rietveld.project'],), ''),
416 ((['git', 'config', '--int', 'branch.master.rietveldissue', '1'],), ''), 416 ((['git', 'config', 'branch.master.rietveldissue', '1'],), ''),
417 ((['git', 'config', 'branch.master.rietveldserver', 417 ((['git', 'config', 'branch.master.rietveldserver',
418 'https://codereview.example.com'],), ''), 418 'https://codereview.example.com'],), ''),
419 ((['git', 419 ((['git',
420 'config', '--int', 'branch.master.rietveldpatchset', '2'],), ''), 420 'config', 'branch.master.rietveldpatchset', '2'],), ''),
421 ] + cls._git_post_upload_calls() 421 ] + cls._git_post_upload_calls()
422 422
423 @classmethod 423 @classmethod
424 def _git_post_upload_calls(cls): 424 def _git_post_upload_calls(cls):
425 return [ 425 return [
426 ((['git', 'rev-parse', 'HEAD'],), 'hash'), 426 ((['git', 'rev-parse', 'HEAD'],), 'hash'),
427 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'), 427 ((['git', 'symbolic-ref', 'HEAD'],), 'hash'),
428 ((['git', 428 ((['git',
429 'config', 'branch.hash.last-upload-hash', 'hash'],), ''), 429 'config', 'branch.hash.last-upload-hash', 'hash'],), ''),
430 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''), 430 ((['git', 'config', 'rietveld.run-post-upload-hook'],), ''),
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 ''), 463 ''),
464 ((['git', 'config', 'rietveld.pending-ref-prefix'],), 464 ((['git', 'config', 'rietveld.pending-ref-prefix'],),
465 ''), 465 ''),
466 ((['git', 466 ((['git',
467 'config', '--local', '--get-regexp', '^svn-remote\\.'],), 467 'config', '--local', '--get-regexp', '^svn-remote\\.'],),
468 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' 468 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n'
469 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), 469 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'),
470 None), 470 None),
471 0)), 471 0)),
472 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 472 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
473 ((['git', 'config', '--int', 473 ((['git', 'config',
474 'branch.working.git-cl-similarity'],), CERR1), 474 'branch.working.git-cl-similarity'],), CERR1),
475 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 475 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
476 ((['git', 'config', '--bool', 476 ((['git', 'config', '--bool',
477 'branch.working.git-find-copies'],), CERR1), 477 'branch.working.git-find-copies'],), CERR1),
478 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), 478 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'),
479 ((['git', 479 ((['git',
480 'config', '--int', 'branch.working.rietveldissue'],), '12345'), 480 'config', 'branch.working.rietveldissue'],), '12345'),
481 ((['git', 481 ((['git',
482 'config', 'rietveld.server'],), 'codereview.example.com'), 482 'config', 'rietveld.server'],), 'codereview.example.com'),
483 ((['git', 483 ((['git',
484 'config', 'branch.working.merge'],), 'refs/heads/master'), 484 'config', 'branch.working.merge'],), 'refs/heads/master'),
485 ((['git', 'config', 'branch.working.remote'],), 'origin'), 485 ((['git', 'config', 'branch.working.remote'],), 'origin'),
486 ((['git', 'config', 'branch.working.merge'],), 486 ((['git', 'config', 'branch.working.merge'],),
487 'refs/heads/master'), 487 'refs/heads/master'),
488 ((['git', 'config', 'branch.working.remote'],), 'origin'), 488 ((['git', 'config', 'branch.working.remote'],), 'origin'),
489 ((['git', 'rev-list', '--merges', 489 ((['git', 'rev-list', '--merges',
490 '--grep=^SVN changes up to revision [0-9]*$', 490 '--grep=^SVN changes up to revision [0-9]*$',
(...skipping 16 matching lines...) Expand all
507 def _dcommit_calls_normal(cls): 507 def _dcommit_calls_normal(cls):
508 return [ 508 return [
509 ((['git', 'rev-parse', '--show-cdup'],), ''), 509 ((['git', 'rev-parse', '--show-cdup'],), ''),
510 ((['git', 'rev-parse', 'HEAD'],), 510 ((['git', 'rev-parse', 'HEAD'],),
511 '00ff397798ea57439712ed7e04ab96e13969ef40'), 511 '00ff397798ea57439712ed7e04ab96e13969ef40'),
512 ((['git', 512 ((['git',
513 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', 513 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...',
514 '.'],), 514 '.'],),
515 'M\tPRESUBMIT.py'), 515 'M\tPRESUBMIT.py'),
516 ((['git', 516 ((['git',
517 'config', '--int', 'branch.working.rietveldpatchset'],), '31137'), 517 'config', 'branch.working.rietveldpatchset'],), '31137'),
518 ((['git', 'config', 'branch.working.rietveldserver'],), 518 ((['git', 'config', 'branch.working.rietveldserver'],),
519 'codereview.example.com'), 519 'codereview.example.com'),
520 ((['git', 'config', 'user.email'],), 'author@example.com'), 520 ((['git', 'config', 'user.email'],), 'author@example.com'),
521 ((['git', 'config', 'rietveld.tree-status-url'],), ''), 521 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
522 ] 522 ]
523 523
524 @classmethod 524 @classmethod
525 def _dcommit_calls_bypassed(cls): 525 def _dcommit_calls_bypassed(cls):
526 return [ 526 return [
527 ((['git', 'config', 'branch.working.rietveldserver'],), 527 ((['git', 'config', 'branch.working.rietveldserver'],),
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 'https://chromium.googlesource.com/my/repo'), 758 'https://chromium.googlesource.com/my/repo'),
759 ((['git', 'config', 'remote.origin.url'],), 759 ((['git', 'config', 'remote.origin.url'],),
760 'https://chromium.googlesource.com/my/repo'), 760 'https://chromium.googlesource.com/my/repo'),
761 ]) 761 ])
762 return calls 762 return calls
763 763
764 @classmethod 764 @classmethod
765 def _gerrit_base_calls(cls, issue=None): 765 def _gerrit_base_calls(cls, issue=None):
766 return [ 766 return [
767 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 767 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
768 ((['git', 'config', '--int', 'branch.master.git-cl-similarity'],), 768 ((['git', 'config', 'branch.master.git-cl-similarity'],),
769 CERR1), 769 CERR1),
770 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 770 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
771 ((['git', 'config', '--bool', 'branch.master.git-find-copies'],), 771 ((['git', 'config', '--bool', 'branch.master.git-find-copies'],),
772 CERR1), 772 CERR1),
773 ] + cls._is_gerrit_calls(True) + [ 773 ] + cls._is_gerrit_calls(True) + [
774 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 774 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
775 ((['git', 'config', '--int', 'branch.master.rietveldissue'],), CERR1), 775 ((['git', 'config', 'branch.master.rietveldissue'],), CERR1),
776 ((['git', 'config', '--int', 'branch.master.gerritissue'],), 776 ((['git', 'config', 'branch.master.gerritissue'],),
777 CERR1 if issue is None else str(issue)), 777 CERR1 if issue is None else str(issue)),
778 ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'), 778 ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
779 ((['git', 'config', 'branch.master.remote'],), 'origin'), 779 ((['git', 'config', 'branch.master.remote'],), 'origin'),
780 ((['get_or_create_merge_base', 'master', 780 ((['get_or_create_merge_base', 'master',
781 'refs/remotes/origin/master'],), 781 'refs/remotes/origin/master'],),
782 'fake_ancestor_sha'), 782 'fake_ancestor_sha'),
783 # Calls to verify branch point is ancestor 783 # Calls to verify branch point is ancestor
784 ] + (cls._gerrit_ensure_auth_calls(issue=issue) + 784 ] + (cls._gerrit_ensure_auth_calls(issue=issue) +
785 cls._git_sanity_checks('fake_ancestor_sha', 'master', 785 cls._git_sanity_checks('fake_ancestor_sha', 'master',
786 get_remote_branch=False)) + [ 786 get_remote_branch=False)) + [
787 ((['git', 'rev-parse', '--show-cdup'],), ''), 787 ((['git', 'rev-parse', '--show-cdup'],), ''),
788 ((['git', 'rev-parse', 'HEAD'],), '12345'), 788 ((['git', 'rev-parse', 'HEAD'],), '12345'),
789 789
790 ((['git', 790 ((['git',
791 'diff', '--name-status', '--no-renames', '-r', 791 'diff', '--name-status', '--no-renames', '-r',
792 'fake_ancestor_sha...', '.'],), 792 'fake_ancestor_sha...', '.'],),
793 'M\t.gitignore\n'), 793 'M\t.gitignore\n'),
794 ((['git', 'config', '--int', 'branch.master.gerritpatchset'],), CERR1), 794 ((['git', 'config', 'branch.master.gerritpatchset'],), CERR1),
795 ] + ([] if issue else [ 795 ] + ([] if issue else [
796 ((['git', 796 ((['git',
797 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 797 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],),
798 'foo'), 798 'foo'),
799 ]) + [ 799 ]) + [
800 ((['git', 'config', 'user.email'],), 'me@example.com'), 800 ((['git', 'config', 'user.email'],), 'me@example.com'),
801 ((['git', 801 ((['git',
802 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 802 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
803 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), 803 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
804 '+dat'), 804 '+dat'),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 'remote: Processing changes: new: 1, done\n' 903 'remote: Processing changes: new: 1, done\n'
904 'remote:\n' 904 'remote:\n'
905 'remote: New Changes:\n' 905 'remote: New Changes:\n'
906 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' 906 'remote: https://chromium-review.googlesource.com/123456 XXX.\n'
907 'remote:\n' 907 'remote:\n'
908 'To https://chromium.googlesource.com/yyy/zzz\n' 908 'To https://chromium.googlesource.com/yyy/zzz\n'
909 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), 909 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')),
910 ] 910 ]
911 if squash: 911 if squash:
912 calls += [ 912 calls += [
913 ((['git', 'config', '--int', 'branch.master.gerritissue', '123456'],), 913 ((['git', 'config', 'branch.master.gerritissue', '123456'],),
914 ''), 914 ''),
915 ((['git', 'config', 'branch.master.gerritserver', 915 ((['git', 'config', 'branch.master.gerritserver',
916 'https://chromium-review.googlesource.com'],), ''), 916 'https://chromium-review.googlesource.com'],), ''),
917 ((['git', 'config', 'branch.master.gerritsquashhash', 917 ((['git', 'config', 'branch.master.gerritsquashhash',
918 'abcdef0123456789'],), ''), 918 'abcdef0123456789'],), ''),
919 ] 919 ]
920 calls += cls._git_post_upload_calls() 920 calls += cls._git_post_upload_calls()
921 return calls 921 return calls
922 922
923 def _run_gerrit_upload_test( 923 def _run_gerrit_upload_test(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) 1271 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True)
1272 1272
1273 if new_branch: 1273 if new_branch:
1274 self.calls = [((['git', 'new-branch', 'master'],), ''),] 1274 self.calls = [((['git', 'new-branch', 'master'],), ''),]
1275 else: 1275 else:
1276 self.calls = [((['git', 'symbolic-ref', 'HEAD'],), 'master')] 1276 self.calls = [((['git', 'symbolic-ref', 'HEAD'],), 'master')]
1277 if not force_codereview: 1277 if not force_codereview:
1278 # These calls detect codereview to use. 1278 # These calls detect codereview to use.
1279 self.calls += [ 1279 self.calls += [
1280 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 1280 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
1281 ((['git', 'config', '--int', 'branch.master.rietveldissue'],), CERR1), 1281 ((['git', 'config', 'branch.master.rietveldissue'],), CERR1),
1282 ((['git', 'config', '--int', 'branch.master.gerritissue'],), CERR1), 1282 ((['git', 'config', 'branch.master.gerritissue'],), CERR1),
1283 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), 1283 ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
1284 ] 1284 ]
1285 1285
1286 if is_gerrit: 1286 if is_gerrit:
1287 if not force_codereview: 1287 if not force_codereview:
1288 self.calls += [ 1288 self.calls += [
1289 ((['git', 'config', 'gerrit.host'],), 'true'), 1289 ((['git', 'config', 'gerrit.host'],), 'true'),
1290 ] 1290 ]
1291 else: 1291 else:
1292 self.calls += [ 1292 self.calls += [
1293 ((['git', 'config', 'gerrit.host'],), CERR1), 1293 ((['git', 'config', 'gerrit.host'],), CERR1),
1294 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 1294 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
1295 ((['git', 'rev-parse', '--show-cdup'],), ''), 1295 ((['git', 'rev-parse', '--show-cdup'],), ''),
1296 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), 1296 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''),
1297 ] 1297 ]
1298 1298
1299 def _common_patch_successful(self, new_branch=False): 1299 def _common_patch_successful(self, new_branch=False):
1300 self._patch_common(new_branch=new_branch) 1300 self._patch_common(new_branch=new_branch)
1301 self.calls += [ 1301 self.calls += [
1302 ((['git', 'apply', '--index', '-p0', '--3way'],), ''), 1302 ((['git', 'apply', '--index', '-p0', '--3way'],), ''),
1303 ((['git', 'commit', '-m', 1303 ((['git', 'commit', '-m',
1304 'Description\n\n' + 1304 'Description\n\n' +
1305 'patch from issue 123456 at patchset 60001 ' + 1305 'patch from issue 123456 at patchset 60001 ' +
1306 '(http://crrev.com/123456#ps60001)'],), ''), 1306 '(http://crrev.com/123456#ps60001)'],), ''),
1307 ((['git', 'config', '--int', 'branch.master.rietveldissue', '123456'],), 1307 ((['git', 'config', 'branch.master.rietveldissue', '123456'],),
1308 ''), 1308 ''),
1309 ((['git', 'config', 'branch.master.rietveldserver'],), CERR1), 1309 ((['git', 'config', 'branch.master.rietveldserver'],), CERR1),
1310 ((['git', 'config', 'branch.master.rietveldserver', 1310 ((['git', 'config', 'branch.master.rietveldserver',
1311 'https://codereview.example.com'],), ''), 1311 'https://codereview.example.com'],), ''),
1312 ((['git', 'config', '--int', 'branch.master.rietveldpatchset', '60001'],), 1312 ((['git', 'config', 'branch.master.rietveldpatchset', '60001'],),
1313 ''), 1313 ''),
1314 ] 1314 ]
1315 1315
1316 def test_patch_successful(self): 1316 def test_patch_successful(self):
1317 self._common_patch_successful() 1317 self._common_patch_successful()
1318 self.assertEqual(git_cl.main(['patch', '123456']), 0) 1318 self.assertEqual(git_cl.main(['patch', '123456']), 0)
1319 1319
1320 def test_patch_successful_new_branch(self): 1320 def test_patch_successful_new_branch(self):
1321 self._common_patch_successful(new_branch=True) 1321 self._common_patch_successful(new_branch=True)
1322 self.assertEqual(git_cl.main(['patch', '-b', 'master', '123456']), 0) 1322 self.assertEqual(git_cl.main(['patch', '-b', 'master', '123456']), 0)
1323 1323
1324 def test_patch_conflict(self): 1324 def test_patch_conflict(self):
1325 self._patch_common() 1325 self._patch_common()
1326 self.calls += [ 1326 self.calls += [
1327 ((['git', 'apply', '--index', '-p0', '--3way'],), CERR1), 1327 ((['git', 'apply', '--index', '-p0', '--3way'],), CERR1),
1328 ] 1328 ]
1329 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) 1329 self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
1330 1330
1331 def test_gerrit_patch_successful(self): 1331 def test_gerrit_patch_successful(self):
1332 self._patch_common(is_gerrit=True) 1332 self._patch_common(is_gerrit=True)
1333 self.calls += [ 1333 self.calls += [
1334 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', 1334 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
1335 'refs/changes/56/123456/7'],), ''), 1335 'refs/changes/56/123456/7'],), ''),
1336 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), 1336 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
1337 ((['git', 'config', '--int', 'branch.master.gerritissue', '123456'],), 1337 ((['git', 'config', 'branch.master.gerritissue', '123456'],),
1338 ''), 1338 ''),
1339 ((['git', 'config', 'branch.master.gerritserver'],), ''), 1339 ((['git', 'config', 'branch.master.gerritserver'],), ''),
1340 ((['git', 'config', 'branch.master.merge'],), 'master'), 1340 ((['git', 'config', 'branch.master.merge'],), 'master'),
1341 ((['git', 'config', 'branch.master.remote'],), 'origin'), 1341 ((['git', 'config', 'branch.master.remote'],), 'origin'),
1342 ((['git', 'config', 'remote.origin.url'],), 1342 ((['git', 'config', 'remote.origin.url'],),
1343 'https://chromium.googlesource.com/my/repo'), 1343 'https://chromium.googlesource.com/my/repo'),
1344 ((['git', 'config', 'branch.master.gerritserver', 1344 ((['git', 'config', 'branch.master.gerritserver',
1345 'https://chromium-review.googlesource.com'],), ''), 1345 'https://chromium-review.googlesource.com'],), ''),
1346 ((['git', 'config', '--int', 'branch.master.gerritpatchset', '7'],), ''), 1346 ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''),
1347 ] 1347 ]
1348 self.assertEqual(git_cl.main(['patch', '123456']), 0) 1348 self.assertEqual(git_cl.main(['patch', '123456']), 0)
1349 1349
1350 def test_patch_force_codereview(self): 1350 def test_patch_force_codereview(self):
1351 self._patch_common(is_gerrit=True, force_codereview=True) 1351 self._patch_common(is_gerrit=True, force_codereview=True)
1352 self.calls += [ 1352 self.calls += [
1353 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', 1353 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
1354 'refs/changes/56/123456/7'],), ''), 1354 'refs/changes/56/123456/7'],), ''),
1355 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), 1355 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
1356 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 1356 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
1357 ((['git', 'config', '--int', 'branch.master.gerritissue', '123456'],), 1357 ((['git', 'config', 'branch.master.gerritissue', '123456'],),
1358 ''), 1358 ''),
1359 ((['git', 'config', 'branch.master.gerritserver'],), ''), 1359 ((['git', 'config', 'branch.master.gerritserver'],), ''),
1360 ((['git', 'config', 'branch.master.merge'],), 'master'), 1360 ((['git', 'config', 'branch.master.merge'],), 'master'),
1361 ((['git', 'config', 'branch.master.remote'],), 'origin'), 1361 ((['git', 'config', 'branch.master.remote'],), 'origin'),
1362 ((['git', 'config', 'remote.origin.url'],), 1362 ((['git', 'config', 'remote.origin.url'],),
1363 'https://chromium.googlesource.com/my/repo'), 1363 'https://chromium.googlesource.com/my/repo'),
1364 ((['git', 'config', 'branch.master.gerritserver', 1364 ((['git', 'config', 'branch.master.gerritserver',
1365 'https://chromium-review.googlesource.com'],), ''), 1365 'https://chromium-review.googlesource.com'],), ''),
1366 ((['git', 'config', '--int', 'branch.master.gerritpatchset', '7'],), ''), 1366 ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''),
1367 ] 1367 ]
1368 self.assertEqual(git_cl.main(['patch', '--gerrit', '123456']), 0) 1368 self.assertEqual(git_cl.main(['patch', '--gerrit', '123456']), 0)
1369 1369
1370 def test_gerrit_patch_url_successful(self): 1370 def test_gerrit_patch_url_successful(self):
1371 self._patch_common(is_gerrit=True) 1371 self._patch_common(is_gerrit=True)
1372 self.calls += [ 1372 self.calls += [
1373 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo', 1373 ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
1374 'refs/changes/56/123456/1'],), ''), 1374 'refs/changes/56/123456/1'],), ''),
1375 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''), 1375 ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
1376 ((['git', 'config', '--int', 'branch.master.gerritissue', '123456'],), 1376 ((['git', 'config', 'branch.master.gerritissue', '123456'],),
1377 ''), 1377 ''),
1378 ((['git', 'config', 'branch.master.gerritserver', 1378 ((['git', 'config', 'branch.master.gerritserver',
1379 'https://chromium-review.googlesource.com'],), ''), 1379 'https://chromium-review.googlesource.com'],), ''),
1380 ((['git', 'config', '--int', 'branch.master.gerritpatchset', '1'],), ''), 1380 ((['git', 'config', 'branch.master.gerritpatchset', '1'],), ''),
1381 ] 1381 ]
1382 self.assertEqual(git_cl.main( 1382 self.assertEqual(git_cl.main(
1383 ['patch', 'https://chromium-review.googlesource.com/#/c/123456/1']), 0) 1383 ['patch', 'https://chromium-review.googlesource.com/#/c/123456/1']), 0)
1384 1384
1385 def test_gerrit_patch_conflict(self): 1385 def test_gerrit_patch_conflict(self):
1386 self._patch_common(is_gerrit=True) 1386 self._patch_common(is_gerrit=True)
1387 self.mock(git_cl, 'DieWithError', 1387 self.mock(git_cl, 'DieWithError',
1388 lambda msg: self._mocked_call(['DieWithError', msg])) 1388 lambda msg: self._mocked_call(['DieWithError', msg]))
1389 class SystemExitMock(Exception): 1389 class SystemExitMock(Exception):
1390 pass 1390 pass
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 def test_gerrit_ensure_authenticated_skipped(self): 1489 def test_gerrit_ensure_authenticated_skipped(self):
1490 cl = self._test_gerrit_ensure_authenticated_common( 1490 cl = self._test_gerrit_ensure_authenticated_common(
1491 auth={}, skip_auth_check=True) 1491 auth={}, skip_auth_check=True)
1492 self.assertIsNone(cl.EnsureAuthenticated(force=False)) 1492 self.assertIsNone(cl.EnsureAuthenticated(force=False))
1493 1493
1494 def test_cmd_set_commit_rietveld(self): 1494 def test_cmd_set_commit_rietveld(self):
1495 self.mock(git_cl._RietveldChangelistImpl, 'SetFlags', 1495 self.mock(git_cl._RietveldChangelistImpl, 'SetFlags',
1496 lambda _, v: self._mocked_call(['SetFlags', v])) 1496 lambda _, v: self._mocked_call(['SetFlags', v]))
1497 self.calls = [ 1497 self.calls = [
1498 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1498 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1499 ((['git', 'config', '--int', 'branch.feature.rietveldissue'],), '123'), 1499 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'),
1500 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1500 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1501 ((['git', 'config', 'rietveld.server'],), ''), 1501 ((['git', 'config', 'rietveld.server'],), ''),
1502 ((['git', 'config', 'rietveld.server'],), ''), 1502 ((['git', 'config', 'rietveld.server'],), ''),
1503 ((['git', 'config', 'branch.feature.rietveldserver'],), 1503 ((['git', 'config', 'branch.feature.rietveldserver'],),
1504 'https://codereview.chromium.org'), 1504 'https://codereview.chromium.org'),
1505 ((['SetFlags', {'commit': '1', 'cq_dry_run': '0'}], ), ''), 1505 ((['SetFlags', {'commit': '1', 'cq_dry_run': '0'}], ), ''),
1506 ] 1506 ]
1507 self.assertEqual(0, git_cl.main(['set-commit'])) 1507 self.assertEqual(0, git_cl.main(['set-commit']))
1508 1508
1509 def _cmd_set_commit_gerrit_common(self, vote): 1509 def _cmd_set_commit_gerrit_common(self, vote):
1510 self.mock(git_cl.gerrit_util, 'SetReview', 1510 self.mock(git_cl.gerrit_util, 'SetReview',
1511 lambda h, i, labels: self._mocked_call( 1511 lambda h, i, labels: self._mocked_call(
1512 ['SetReview', h, i, labels])) 1512 ['SetReview', h, i, labels]))
1513 self.calls = [ 1513 self.calls = [
1514 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1514 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1515 ((['git', 'config', '--int', 'branch.feature.rietveldissue'],), CERR1), 1515 ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1),
1516 ((['git', 'config', '--int', 'branch.feature.gerritissue'],), '123'), 1516 ((['git', 'config', 'branch.feature.gerritissue'],), '123'),
1517 ((['git', 'config', 'branch.feature.gerritserver'],), 1517 ((['git', 'config', 'branch.feature.gerritserver'],),
1518 'https://chromium-review.googlesource.com'), 1518 'https://chromium-review.googlesource.com'),
1519 ((['SetReview', 'chromium-review.googlesource.com', 123, 1519 ((['SetReview', 'chromium-review.googlesource.com', 123,
1520 {'Commit-Queue': vote}],), ''), 1520 {'Commit-Queue': vote}],), ''),
1521 ] 1521 ]
1522 1522
1523 def test_cmd_set_commit_gerrit_clear(self): 1523 def test_cmd_set_commit_gerrit_clear(self):
1524 self._cmd_set_commit_gerrit_common(0) 1524 self._cmd_set_commit_gerrit_common(0)
1525 self.assertEqual(0, git_cl.main(['set-commit', '-c'])) 1525 self.assertEqual(0, git_cl.main(['set-commit', '-c']))
1526 1526
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 1661
1662 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1662 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1663 self.mock(git_cl.Changelist, 'GetDescription', 1663 self.mock(git_cl.Changelist, 'GetDescription',
1664 lambda *args: current_desc) 1664 lambda *args: current_desc)
1665 self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote', 1665 self.mock(git_cl._GerritChangelistImpl, 'UpdateDescriptionRemote',
1666 UpdateDescriptionRemote) 1666 UpdateDescriptionRemote)
1667 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor) 1667 self.mock(git_cl.gclient_utils, 'RunEditor', RunEditor)
1668 1668
1669 self.calls = [ 1669 self.calls = [
1670 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1670 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1671 ((['git', 'config', '--int', 'branch.feature.gerritissue'],), '123'), 1671 ((['git', 'config', 'branch.feature.gerritissue'],), '123'),
1672 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), 1672 ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
1673 ((['git', 'config', 'rietveld.bug-prefix'],), CERR1), 1673 ((['git', 'config', 'rietveld.bug-prefix'],), CERR1),
1674 ((['git', 'config', 'core.editor'],), 'vi'), 1674 ((['git', 'config', 'core.editor'],), 'vi'),
1675 ] 1675 ]
1676 self.assertEqual(0, git_cl.main(['description', '--gerrit'])) 1676 self.assertEqual(0, git_cl.main(['description', '--gerrit']))
1677 1677
1678 def test_description_set_stdin(self): 1678 def test_description_set_stdin(self):
1679 out = StringIO.StringIO() 1679 out = StringIO.StringIO()
1680 self.mock(git_cl.sys, 'stdout', out) 1680 self.mock(git_cl.sys, 'stdout', out)
1681 1681
1682 self.mock(git_cl, 'Changelist', ChangelistMock) 1682 self.mock(git_cl, 'Changelist', ChangelistMock)
1683 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman')) 1683 self.mock(git_cl.sys, 'stdin', StringIO.StringIO('hi \r\n\t there\n\nman'))
1684 1684
1685 self.assertEqual(0, git_cl.main(['description', '-n', '-'])) 1685 self.assertEqual(0, git_cl.main(['description', '-n', '-']))
1686 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc) 1686 self.assertEqual('hi\n\t there\n\nman', ChangelistMock.desc)
1687 1687
1688 def test_archive(self): 1688 def test_archive(self):
1689 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1689 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1690 1690
1691 self.calls = \ 1691 self.calls = \
1692 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), 1692 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
1693 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'), 1693 'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
1694 ((['git', 'config', '--int', 'branch.master.rietveldissue'],), '1'), 1694 ((['git', 'config', 'branch.master.rietveldissue'],), '1'),
1695 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), 1695 ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
1696 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 1696 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
1697 ((['git', 'config', '--int', 'branch.foo.rietveldissue'],), '456'), 1697 ((['git', 'config', 'branch.foo.rietveldissue'],), '456'),
1698 ((['git', 'config', '--int', 'branch.bar.rietveldissue'],), CERR1), 1698 ((['git', 'config', 'branch.bar.rietveldissue'],), CERR1),
1699 ((['git', 'config', '--int', 'branch.bar.gerritissue'],), '789'), 1699 ((['git', 'config', 'branch.bar.gerritissue'],), '789'),
1700 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), 1700 ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
1701 ((['git', 'tag', 'git-cl-archived-456-foo', 'foo'],), ''), 1701 ((['git', 'tag', 'git-cl-archived-456-foo', 'foo'],), ''),
1702 ((['git', 'branch', '-D', 'foo'],), '')] 1702 ((['git', 'branch', '-D', 'foo'],), '')]
1703 1703
1704 class MockChangelist(): 1704 class MockChangelist():
1705 def __init__(self, branch, issue): 1705 def __init__(self, branch, issue):
1706 self.branch = branch 1706 self.branch = branch
1707 self.issue = issue 1707 self.issue = issue
1708 def GetBranch(self): 1708 def GetBranch(self):
1709 return self.branch 1709 return self.branch
1710 def GetIssue(self): 1710 def GetIssue(self):
1711 return self.issue 1711 return self.issue
1712 1712
1713 self.mock(git_cl, 'get_cl_statuses', 1713 self.mock(git_cl, 'get_cl_statuses',
1714 lambda branches, fine_grained, max_processes: 1714 lambda branches, fine_grained, max_processes:
1715 [(MockChangelist('master', 1), 'open'), 1715 [(MockChangelist('master', 1), 'open'),
1716 (MockChangelist('foo', 456), 'closed'), 1716 (MockChangelist('foo', 456), 'closed'),
1717 (MockChangelist('bar', 789), 'open')]) 1717 (MockChangelist('bar', 789), 'open')])
1718 1718
1719 self.assertEqual(0, git_cl.main(['archive', '-f'])) 1719 self.assertEqual(0, git_cl.main(['archive', '-f']))
1720 1720
1721 def test_archive_current_branch_fails(self): 1721 def test_archive_current_branch_fails(self):
1722 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 1722 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
1723 self.calls = \ 1723 self.calls = \
1724 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],), 1724 [((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
1725 'refs/heads/master'), 1725 'refs/heads/master'),
1726 ((['git', 'config', '--int', 'branch.master.rietveldissue'],), '1'), 1726 ((['git', 'config', 'branch.master.rietveldissue'],), '1'),
1727 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), 1727 ((['git', 'config', 'rietveld.autoupdate'],), CERR1),
1728 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), 1728 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
1729 ((['git', 'symbolic-ref', 'HEAD'],), 'master')] 1729 ((['git', 'symbolic-ref', 'HEAD'],), 'master')]
1730 1730
1731 class MockChangelist(): 1731 class MockChangelist():
1732 def __init__(self, branch, issue): 1732 def __init__(self, branch, issue):
1733 self.branch = branch 1733 self.branch = branch
1734 self.issue = issue 1734 self.issue = issue
1735 def GetBranch(self): 1735 def GetBranch(self):
1736 return self.branch 1736 return self.branch
1737 def GetIssue(self): 1737 def GetIssue(self):
1738 return self.issue 1738 return self.issue
1739 1739
1740 self.mock(git_cl, 'get_cl_statuses', 1740 self.mock(git_cl, 'get_cl_statuses',
1741 lambda branches, fine_grained, max_processes: 1741 lambda branches, fine_grained, max_processes:
1742 [(MockChangelist('master', 1), 'closed')]) 1742 [(MockChangelist('master', 1), 'closed')])
1743 1743
1744 self.assertEqual(1, git_cl.main(['archive', '-f'])) 1744 self.assertEqual(1, git_cl.main(['archive', '-f']))
1745 1745
1746 def test_cmd_issue_erase_existing(self): 1746 def test_cmd_issue_erase_existing(self):
1747 out = StringIO.StringIO() 1747 out = StringIO.StringIO()
1748 self.mock(git_cl.sys, 'stdout', out) 1748 self.mock(git_cl.sys, 'stdout', out)
1749 self.calls = [ 1749 self.calls = [
1750 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1750 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1751 ((['git', 'config', '--int', 'branch.feature.rietveldissue'],), CERR1), 1751 ((['git', 'config', 'branch.feature.rietveldissue'],), CERR1),
1752 ((['git', 'config', '--int', 'branch.feature.gerritissue'],), '123'), 1752 ((['git', 'config', 'branch.feature.gerritissue'],), '123'),
1753 # Let this command raise exception (retcode=1) - it should be ignored. 1753 # Let this command raise exception (retcode=1) - it should be ignored.
1754 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],), 1754 ((['git', 'config', '--unset', 'branch.feature.last-upload-hash'],),
1755 CERR1), 1755 CERR1),
1756 ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''), 1756 ((['git', 'config', '--unset', 'branch.feature.gerritissue'],), ''),
1757 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''), 1757 ((['git', 'config', '--unset', 'branch.feature.gerritpatchset'],), ''),
1758 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''), 1758 ((['git', 'config', '--unset', 'branch.feature.gerritserver'],), ''),
1759 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],), 1759 ((['git', 'config', '--unset', 'branch.feature.gerritsquashhash'],),
1760 ''), 1760 ''),
1761 ] 1761 ]
1762 self.assertEqual(0, git_cl.main(['issue', '0'])) 1762 self.assertEqual(0, git_cl.main(['issue', '0']))
1763 1763
1764 def test_cmd_issue_json(self): 1764 def test_cmd_issue_json(self):
1765 out = StringIO.StringIO() 1765 out = StringIO.StringIO()
1766 self.mock(git_cl.sys, 'stdout', out) 1766 self.mock(git_cl.sys, 'stdout', out)
1767 self.calls = [ 1767 self.calls = [
1768 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1768 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1769 ((['git', 'config', '--int', 'branch.feature.rietveldissue'],), '123'), 1769 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'),
1770 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1770 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1771 ((['git', 'config', 'rietveld.server'],), 1771 ((['git', 'config', 'rietveld.server'],),
1772 'https://codereview.chromium.org'), 1772 'https://codereview.chromium.org'),
1773 ((['git', 'config', 'branch.feature.rietveldserver'],), ''), 1773 ((['git', 'config', 'branch.feature.rietveldserver'],), ''),
1774 (('write_json', 'output.json', 1774 (('write_json', 'output.json',
1775 {'issue': 123, 'issue_url': 'https://codereview.chromium.org/123'}), 1775 {'issue': 123, 'issue_url': 'https://codereview.chromium.org/123'}),
1776 ''), 1776 ''),
1777 ] 1777 ]
1778 self.assertEqual(0, git_cl.main(['issue', '--json', 'output.json'])) 1778 self.assertEqual(0, git_cl.main(['issue', '--json', 'output.json']))
1779 1779
1780 def test_git_cl_try_default(self): 1780 def test_git_cl_try_default(self):
1781 self.mock(git_cl.Changelist, 'GetChange', 1781 self.mock(git_cl.Changelist, 'GetChange',
1782 lambda _, *a: ( 1782 lambda _, *a: (
1783 self._mocked_call(['GetChange']+list(a)))) 1783 self._mocked_call(['GetChange']+list(a))))
1784 self.mock(git_cl.presubmit_support, 'DoGetTryMasters', 1784 self.mock(git_cl.presubmit_support, 'DoGetTryMasters',
1785 lambda *_, **__: ( 1785 lambda *_, **__: (
1786 self._mocked_call(['DoGetTryMasters']))) 1786 self._mocked_call(['DoGetTryMasters'])))
1787 self.mock(git_cl.presubmit_support, 'DoGetTrySlaves', 1787 self.mock(git_cl.presubmit_support, 'DoGetTrySlaves',
1788 lambda *_, **__: ( 1788 lambda *_, **__: (
1789 self._mocked_call(['DoGetTrySlaves']))) 1789 self._mocked_call(['DoGetTrySlaves'])))
1790 self.mock(git_cl._RietveldChangelistImpl, 'SetCQState', 1790 self.mock(git_cl._RietveldChangelistImpl, 'SetCQState',
1791 lambda _, s: self._mocked_call(['SetCQState', s])) 1791 lambda _, s: self._mocked_call(['SetCQState', s]))
1792 self.calls = [ 1792 self.calls = [
1793 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), 1793 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'),
1794 ((['git', 'config', '--int', 'branch.feature.rietveldissue'],), '123'), 1794 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'),
1795 ((['git', 'config', 'rietveld.autoupdate'],), ''), 1795 ((['git', 'config', 'rietveld.autoupdate'],), ''),
1796 ((['git', 'config', 'rietveld.server'],), 1796 ((['git', 'config', 'rietveld.server'],),
1797 'https://codereview.chromium.org'), 1797 'https://codereview.chromium.org'),
1798 ((['git', 'config', 'branch.feature.rietveldserver'],), ''), 1798 ((['git', 'config', 'branch.feature.rietveldserver'],), ''),
1799 ((['git', 'config', 'branch.feature.merge'],), 'feature'), 1799 ((['git', 'config', 'branch.feature.merge'],), 'feature'),
1800 ((['git', 'config', 'branch.feature.remote'],), 'origin'), 1800 ((['git', 'config', 'branch.feature.remote'],), 'origin'),
1801 ((['get_or_create_merge_base', 'feature', 'feature'],), 1801 ((['get_or_create_merge_base', 'feature', 'feature'],),
1802 'fake_ancestor_sha'), 1802 'fake_ancestor_sha'),
1803 ((['GetChange', 'fake_ancestor_sha', None], ), 1803 ((['GetChange', 'fake_ancestor_sha', None], ),
1804 git_cl.presubmit_support.GitChange( 1804 git_cl.presubmit_support.GitChange(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), 1857 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],),
1858 ''), 1858 ''),
1859 ] 1859 ]
1860 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) 1860 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True)
1861 1861
1862 1862
1863 if __name__ == '__main__': 1863 if __name__ == '__main__':
1864 git_cl.logging.basicConfig( 1864 git_cl.logging.basicConfig(
1865 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1865 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1866 unittest.main() 1866 unittest.main()
OLDNEW
« no previous file with comments | « git_cl.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698