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

Side by Side Diff: tests/git_cl_test.py

Issue 1891233003: Support getting changes of non-HEAD branches (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@branch-to-cl
Patch Set: fix Created 4 years, 8 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') | tests/presubmit_unittest.py » ('j') | 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 ((['git', 'config', 'branch.master.rietveldissue'],), ''), 306 ((['git', 'config', 'branch.master.rietveldissue'],), ''),
307 ((['git', 'config', 'branch.master.gerritissue'],), ''), 307 ((['git', 'config', 'branch.master.gerritissue'],), ''),
308 ((['git', 'config', 'rietveld.server'],), 308 ((['git', 'config', 'rietveld.server'],),
309 'codereview.example.com'), 309 'codereview.example.com'),
310 ((['git', 'config', 'branch.master.merge'],), 'master'), 310 ((['git', 'config', 'branch.master.merge'],), 'master'),
311 ((['git', 'config', 'branch.master.remote'],), 'origin'), 311 ((['git', 'config', 'branch.master.remote'],), 'origin'),
312 ((['get_or_create_merge_base', 'master', 'master'],), 312 ((['get_or_create_merge_base', 'master', 'master'],),
313 'fake_ancestor_sha'), 313 'fake_ancestor_sha'),
314 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ 314 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [
315 ((['git', 'rev-parse', '--show-cdup'],), ''), 315 ((['git', 'rev-parse', '--show-cdup'],), ''),
316 ((['git', 'rev-parse', 'HEAD'],), '12345'), 316 ((['git', 'rev-parse', 'refs/heads/master'],), '12345'),
317 ((['git', 'diff', '--name-status', '--no-renames', '-r', 317 ((['git', 'diff', '--name-status', '--no-renames', '-r',
318 'fake_ancestor_sha...', '.'],), 318 'fake_ancestor_sha...refs/heads/master', '.'],),
319 'M\t.gitignore\n'), 319 'M\t.gitignore\n'),
320 ((['git', 'config', 'branch.master.rietveldpatchset'],), 320 ((['git', 'config', 'branch.master.rietveldpatchset'],),
321 ''), 321 ''),
322 ((['git', 'log', '--pretty=format:%s%n%n%b', 322 ((['git', 'log', '--pretty=format:%s%n%n%b',
323 'fake_ancestor_sha...'],), 323 'fake_ancestor_sha...refs/heads/master'],),
324 'foo'), 324 'foo'),
325 ((['git', 'config', 'user.email'],), 'me@example.com'), 325 ((['git', 'config', 'user.email'],), 'me@example.com'),
326 stat_call, 326 stat_call,
327 ((['git', 'log', '--pretty=format:%s\n\n%b', 327 ((['git', 'log', '--pretty=format:%s\n\n%b',
328 'fake_ancestor_sha..HEAD'],), 328 'fake_ancestor_sha..HEAD'],),
329 'desc\n'), 329 'desc\n'),
330 ((['git', 'config', 'rietveld.bug-prefix'],), ''), 330 ((['git', 'config', 'rietveld.bug-prefix'],), ''),
331 ] 331 ]
332 332
333 @classmethod 333 @classmethod
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 ] 376 ]
377 377
378 @staticmethod 378 @staticmethod
379 def _git_sanity_checks(diff_base, working_branch, get_remote_branch=True): 379 def _git_sanity_checks(diff_base, working_branch, get_remote_branch=True):
380 fake_ancestor = 'fake_ancestor' 380 fake_ancestor = 'fake_ancestor'
381 fake_cl = 'fake_cl_for_patch' 381 fake_cl = 'fake_cl_for_patch'
382 return [ 382 return [
383 ((['git', 383 ((['git',
384 'rev-parse', '--verify', diff_base],), fake_ancestor), 384 'rev-parse', '--verify', diff_base],), fake_ancestor),
385 ((['git', 385 ((['git',
386 'merge-base', fake_ancestor, 'HEAD'],), fake_ancestor), 386 'merge-base', fake_ancestor, 'refs/heads/'+working_branch],),
387 fake_ancestor),
387 ((['git', 388 ((['git',
388 'rev-list', '^' + fake_ancestor, 'HEAD'],), fake_cl), 389 'rev-list', '^' + fake_ancestor, 'refs/heads/'+working_branch],),
390 fake_cl),
389 # Mock a config miss (error code 1) 391 # Mock a config miss (error code 1)
390 ((['git', 392 ((['git',
391 'config', 'gitcl.remotebranch'],), (('', None), 1)), 393 'config', 'gitcl.remotebranch'],), (('', None), 1)),
392 ] + ([ 394 ] + ([
393 # Call to GetRemoteBranch() 395 # Call to GetRemoteBranch()
394 ((['git', 396 ((['git',
395 'config', 'branch.%s.merge' % working_branch],), 397 'config', 'branch.%s.merge' % working_branch],),
396 'refs/heads/master'), 398 'refs/heads/master'),
397 ((['git', 399 ((['git',
398 'config', 'branch.%s.remote' % working_branch],), 'origin'), 400 'config', 'branch.%s.remote' % working_branch],), 'origin'),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), 444 '3fc18b62c4966193eb435baabe2d18a3810ec82e'),
443 ((['git', 445 ((['git',
444 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', 446 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e',
445 'refs/remotes/origin/master'],), ''), 447 'refs/remotes/origin/master'],), ''),
446 ((['git', 448 ((['git',
447 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), 449 'merge-base', 'refs/remotes/origin/master', 'HEAD'],),
448 'fake_ancestor_sha'), 450 'fake_ancestor_sha'),
449 ] 451 ]
450 452
451 @classmethod 453 @classmethod
452 def _dcommit_calls_normal(cls): 454 def _dcommit_calls_normal(cls, working_branch='master'):
453 return [ 455 return [
454 ((['git', 'rev-parse', '--show-cdup'],), ''), 456 ((['git', 'rev-parse', '--show-cdup'],), ''),
455 ((['git', 'rev-parse', 'HEAD'],), 457 ((['git', 'rev-parse', 'refs/heads/'+working_branch],),
456 '00ff397798ea57439712ed7e04ab96e13969ef40'), 458 '00ff397798ea57439712ed7e04ab96e13969ef40'),
457 ((['git', 459 ((['git',
458 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', 460 'diff', '--name-status', '--no-renames', '-r',
459 '.'],), 461 'fake_ancestor_sha...refs/heads/'+working_branch, '.'],),
460 'M\tPRESUBMIT.py'), 462 'M\tPRESUBMIT.py'),
461 ((['git', 463 ((['git',
462 'config', 'branch.working.rietveldpatchset'],), '31137'), 464 'config', 'branch.working.rietveldpatchset'],), '31137'),
463 ((['git', 'config', 'branch.working.rietveldserver'],), 465 ((['git', 'config', 'branch.working.rietveldserver'],),
464 'codereview.example.com'), 466 'codereview.example.com'),
465 ((['git', 'config', 'user.email'],), 'author@example.com'), 467 ((['git', 'config', 'user.email'],), 'author@example.com'),
466 ((['git', 'config', 'rietveld.tree-status-url'],), ''), 468 ((['git', 'config', 'rietveld.tree-status-url'],), ''),
467 ] 469 ]
468 470
469 @classmethod 471 @classmethod
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 '--similarity.\n', 660 '--similarity.\n',
659 stdout.getvalue()) 661 stdout.getvalue())
660 self.assertEqual( 662 self.assertEqual(
661 'Must specify reviewers to send email.\n', stderr.getvalue()) 663 'Must specify reviewers to send email.\n', stderr.getvalue())
662 664
663 def test_dcommit(self): 665 def test_dcommit(self):
664 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 666 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
665 self.calls = ( 667 self.calls = (
666 self._dcommit_calls_1() + 668 self._dcommit_calls_1() +
667 self._git_sanity_checks('fake_ancestor_sha', 'working') + 669 self._git_sanity_checks('fake_ancestor_sha', 'working') +
668 self._dcommit_calls_normal() + 670 self._dcommit_calls_normal('working') +
669 self._dcommit_calls_3()) 671 self._dcommit_calls_3())
670 git_cl.main(['dcommit']) 672 git_cl.main(['dcommit'])
671 673
672 def test_dcommit_bypass_hooks(self): 674 def test_dcommit_bypass_hooks(self):
673 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) 675 self.mock(git_cl.sys, 'stdout', StringIO.StringIO())
674 self.calls = ( 676 self.calls = (
675 self._dcommit_calls_1() + 677 self._dcommit_calls_1() +
676 self._dcommit_calls_bypassed() + 678 self._dcommit_calls_bypassed() +
677 self._dcommit_calls_3()) 679 self._dcommit_calls_3())
678 git_cl.main(['dcommit', '--bypass-hooks']) 680 git_cl.main(['dcommit', '--bypass-hooks'])
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'), 718 ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
717 ((['git', 'config', 'branch.master.remote'],), 'origin'), 719 ((['git', 'config', 'branch.master.remote'],), 'origin'),
718 ((['get_or_create_merge_base', 'master', 720 ((['get_or_create_merge_base', 'master',
719 'refs/remotes/origin/master'],), 721 'refs/remotes/origin/master'],),
720 'fake_ancestor_sha'), 722 'fake_ancestor_sha'),
721 # Calls to verify branch point is ancestor 723 # Calls to verify branch point is ancestor
722 ] + (cls._gerrit_ensure_auth_calls(issue=issue) + 724 ] + (cls._gerrit_ensure_auth_calls(issue=issue) +
723 cls._git_sanity_checks('fake_ancestor_sha', 'master', 725 cls._git_sanity_checks('fake_ancestor_sha', 'master',
724 get_remote_branch=False)) + [ 726 get_remote_branch=False)) + [
725 ((['git', 'rev-parse', '--show-cdup'],), ''), 727 ((['git', 'rev-parse', '--show-cdup'],), ''),
726 ((['git', 'rev-parse', 'HEAD'],), '12345'), 728 ((['git', 'rev-parse', 'refs/heads/master'],), '12345'),
727 729
728 ((['git', 730 ((['git',
729 'diff', '--name-status', '--no-renames', '-r', 731 'diff', '--name-status', '--no-renames', '-r',
730 'fake_ancestor_sha...', '.'],), 732 'fake_ancestor_sha...refs/heads/master', '.'],),
731 'M\t.gitignore\n'), 733 'M\t.gitignore\n'),
732 ((['git', 'config', 'branch.master.gerritpatchset'],), ''), 734 ((['git', 'config', 'branch.master.gerritpatchset'],), ''),
733 ] + ([] if issue else [ 735 ] + ([] if issue else [
734 ((['git', 736 ((['git',
735 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), 737 'log', '--pretty=format:%s%n%n%b',
738 'fake_ancestor_sha...refs/heads/master'],),
736 'foo'), 739 'foo'),
737 ]) + [ 740 ]) + [
738 ((['git', 'config', 'user.email'],), 'me@example.com'), 741 ((['git', 'config', 'user.email'],), 'me@example.com'),
739 ((['git', 742 ((['git',
740 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', 743 'diff', '--no-ext-diff', '--stat', '--find-copies-harder',
741 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), 744 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],),
742 '+dat'), 745 '+dat'),
743 ] 746 ]
744 747
745 @classmethod 748 @classmethod
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 # TODO(tandrii): consider testing just set-commit and set-commit --clear, 1378 # TODO(tandrii): consider testing just set-commit and set-commit --clear,
1376 # but without copy-pasting tons of expectations, as modifying them later is 1379 # but without copy-pasting tons of expectations, as modifying them later is
1377 # super tedious. 1380 # super tedious.
1378 self.assertEqual(0, git_cl.main(['set-commit', '-d'])) 1381 self.assertEqual(0, git_cl.main(['set-commit', '-d']))
1379 1382
1380 1383
1381 if __name__ == '__main__': 1384 if __name__ == '__main__':
1382 git_cl.logging.basicConfig( 1385 git_cl.logging.basicConfig(
1383 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) 1386 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR)
1384 unittest.main() 1387 unittest.main()
OLDNEW
« no previous file with comments | « scm.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698