OLD | NEW |
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 156 |
157 if find_copies: | 157 if find_copies: |
158 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 158 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
159 '--find-copies-harder', '-l100000', '-C'+similarity, | 159 '--find-copies-harder', '-l100000', '-C'+similarity, |
160 'fake_ancestor_sha', 'HEAD'],), '+dat') | 160 'fake_ancestor_sha', 'HEAD'],), '+dat') |
161 else: | 161 else: |
162 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', | 162 stat_call = ((['git', 'diff', '--no-ext-diff', '--stat', |
163 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') | 163 '-M'+similarity, 'fake_ancestor_sha', 'HEAD'],), '+dat') |
164 | 164 |
165 return [ | 165 return [ |
| 166 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
| 167 ((['git', 'config', 'rietveld.server'],), |
| 168 'codereview.example.com'), |
166 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 169 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
167 similarity_call, | 170 similarity_call, |
168 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 171 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
169 find_copies_call, | 172 find_copies_call, |
170 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
171 ((['git', 'config', 'rietveld.server'],), | |
172 'codereview.example.com'), | |
173 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 173 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
174 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | |
175 ((['git', 'config', 'branch.master.gerritissue'],), ''), | |
176 ((['git', 'config', 'gerrit.host'],), ''), | |
177 ((['git', 'config', 'branch.master.merge'],), 'master'), | 174 ((['git', 'config', 'branch.master.merge'],), 'master'), |
178 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 175 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
179 ((['get_or_create_merge_base', 'master', 'master'],), | 176 ((['get_or_create_merge_base', 'master', 'master'],), |
180 'fake_ancestor_sha'), | 177 'fake_ancestor_sha'), |
| 178 ((['git', 'config', 'gerrit.host'],), ''), |
| 179 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
181 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 180 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
182 ((['git', 'rev-parse', '--show-cdup'],), ''), | 181 ((['git', 'rev-parse', '--show-cdup'],), ''), |
183 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 182 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
184 ((['git', 'diff', '--name-status', '--no-renames', '-r', | 183 ((['git', 'diff', '--name-status', '--no-renames', '-r', |
185 'fake_ancestor_sha...', '.'],), | 184 'fake_ancestor_sha...', '.'],), |
186 'M\t.gitignore\n'), | 185 'M\t.gitignore\n'), |
187 ((['git', 'config', 'branch.master.rietveldpatchset'],), | 186 ((['git', 'config', 'branch.master.rietveldpatchset'],), |
188 ''), | 187 ''), |
189 ((['git', 'log', '--pretty=format:%s%n%n%b', | 188 ((['git', 'log', '--pretty=format:%s%n%n%b', |
190 'fake_ancestor_sha...'],), | 189 'fake_ancestor_sha...'],), |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 ((['git', 'config', 'rietveld.autoupdate'],), | 272 ((['git', 'config', 'rietveld.autoupdate'],), |
274 ''), | 273 ''), |
275 ((['git', 'config', 'rietveld.pending-ref-prefix'],), | 274 ((['git', 'config', 'rietveld.pending-ref-prefix'],), |
276 ''), | 275 ''), |
277 ((['git', | 276 ((['git', |
278 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | 277 'config', '--local', '--get-regexp', '^svn-remote\\.'],), |
279 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' | 278 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' |
280 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), | 279 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), |
281 None), | 280 None), |
282 0)), | 281 0)), |
| 282 ((['git', |
| 283 'config', 'rietveld.server'],), 'codereview.example.com'), |
283 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 284 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
284 ((['git', 'config', '--int', '--get', | 285 ((['git', 'config', '--int', '--get', |
285 'branch.working.git-cl-similarity'],), ''), | 286 'branch.working.git-cl-similarity'],), ''), |
286 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 287 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
287 ((['git', 'config', '--int', '--get', | 288 ((['git', 'config', '--int', '--get', |
288 'branch.working.git-find-copies'],), ''), | 289 'branch.working.git-find-copies'],), ''), |
289 ((['git', | |
290 'config', 'rietveld.server'],), 'codereview.example.com'), | |
291 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | 290 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), |
292 ((['git', | 291 ((['git', |
293 'config', 'branch.working.rietveldissue'],), '12345'), | |
294 ((['git', | |
295 'config', 'branch.working.merge'],), 'refs/heads/master'), | 292 'config', 'branch.working.merge'],), 'refs/heads/master'), |
296 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 293 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
297 ((['git', 'config', 'branch.working.merge'],), | 294 ((['git', 'config', 'branch.working.merge'],), |
298 'refs/heads/master'), | 295 'refs/heads/master'), |
299 ((['git', 'config', 'branch.working.remote'],), 'origin'), | 296 ((['git', 'config', 'branch.working.remote'],), 'origin'), |
300 ((['git', 'rev-list', '--merges', | 297 ((['git', 'rev-list', '--merges', |
301 '--grep=^SVN changes up to revision [0-9]*$', | 298 '--grep=^SVN changes up to revision [0-9]*$', |
302 'refs/remotes/origin/master^!'],), ''), | 299 'refs/remotes/origin/master^!'],), ''), |
303 ((['git', 'rev-list', '^refs/heads/working', | 300 ((['git', 'rev-list', '^refs/heads/working', |
304 'refs/remotes/origin/master'],), | 301 'refs/remotes/origin/master'],), |
(...skipping 13 matching lines...) Expand all Loading... |
318 def _dcommit_calls_normal(cls): | 315 def _dcommit_calls_normal(cls): |
319 return [ | 316 return [ |
320 ((['git', 'rev-parse', '--show-cdup'],), ''), | 317 ((['git', 'rev-parse', '--show-cdup'],), ''), |
321 ((['git', 'rev-parse', 'HEAD'],), | 318 ((['git', 'rev-parse', 'HEAD'],), |
322 '00ff397798ea57439712ed7e04ab96e13969ef40'), | 319 '00ff397798ea57439712ed7e04ab96e13969ef40'), |
323 ((['git', | 320 ((['git', |
324 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', | 321 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', |
325 '.'],), | 322 '.'],), |
326 'M\tPRESUBMIT.py'), | 323 'M\tPRESUBMIT.py'), |
327 ((['git', | 324 ((['git', |
| 325 'config', 'branch.working.rietveldissue'],), '12345'), |
| 326 ((['git', |
328 'config', 'branch.working.rietveldpatchset'],), '31137'), | 327 'config', 'branch.working.rietveldpatchset'],), '31137'), |
329 ((['git', 'config', 'branch.working.rietveldserver'],), | 328 ((['git', 'config', 'branch.working.rietveldserver'],), |
330 'codereview.example.com'), | 329 'codereview.example.com'), |
331 ((['git', 'config', 'user.email'],), 'author@example.com'), | 330 ((['git', 'config', 'user.email'],), 'author@example.com'), |
332 ((['git', 'config', 'rietveld.tree-status-url'],), ''), | 331 ((['git', 'config', 'rietveld.tree-status-url'],), ''), |
333 ] | 332 ] |
334 | 333 |
335 @classmethod | 334 @classmethod |
336 def _dcommit_calls_bypassed(cls): | 335 def _dcommit_calls_bypassed(cls): |
337 return [ | 336 return [ |
| 337 ((['git', |
| 338 'config', 'branch.working.rietveldissue'],), '12345'), |
338 ((['git', 'config', 'branch.working.rietveldserver'],), | 339 ((['git', 'config', 'branch.working.rietveldserver'],), |
339 'codereview.example.com'), | 340 'codereview.example.com'), |
340 ] | 341 ] |
341 | 342 |
342 @classmethod | 343 @classmethod |
343 def _dcommit_calls_3(cls): | 344 def _dcommit_calls_3(cls): |
344 return [ | 345 return [ |
| 346 ((['git', 'config', 'gerrit.host'],), ''), |
345 ((['git', | 347 ((['git', |
346 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 348 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
347 '-l100000', '-C50', 'fake_ancestor_sha', | 349 '-l100000', '-C50', 'fake_ancestor_sha', |
348 'refs/heads/working'],), | 350 'refs/heads/working'],), |
349 (' PRESUBMIT.py | 2 +-\n' | 351 (' PRESUBMIT.py | 2 +-\n' |
350 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), | 352 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), |
351 ((['git', 'show-ref', '--quiet', '--verify', | 353 ((['git', 'show-ref', '--quiet', '--verify', |
352 'refs/heads/git-cl-commit'],), | 354 'refs/heads/git-cl-commit'],), |
353 (('', None), 0)), | 355 (('', None), 0)), |
354 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | 356 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 self.calls = ( | 539 self.calls = ( |
538 self._dcommit_calls_1() + | 540 self._dcommit_calls_1() + |
539 self._dcommit_calls_bypassed() + | 541 self._dcommit_calls_bypassed() + |
540 self._dcommit_calls_3()) | 542 self._dcommit_calls_3()) |
541 git_cl.main(['dcommit', '--bypass-hooks']) | 543 git_cl.main(['dcommit', '--bypass-hooks']) |
542 | 544 |
543 | 545 |
544 @classmethod | 546 @classmethod |
545 def _gerrit_base_calls(cls): | 547 def _gerrit_base_calls(cls): |
546 return [ | 548 return [ |
| 549 ((['git', 'config', 'rietveld.autoupdate'],), |
| 550 ''), |
| 551 ((['git', |
| 552 'config', 'rietveld.server'],), 'codereview.example.com'), |
547 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 553 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
548 ((['git', 'config', '--int', '--get', | 554 ((['git', 'config', '--int', '--get', |
549 'branch.master.git-cl-similarity'],), ''), | 555 'branch.master.git-cl-similarity'],), ''), |
550 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 556 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
551 ((['git', 'config', '--int', '--get', | 557 ((['git', 'config', '--int', '--get', |
552 'branch.master.git-find-copies'],), ''), | 558 'branch.master.git-find-copies'],), ''), |
553 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
554 ((['git', 'config', 'rietveld.server'],), ''), | |
555 ((['git', 'config', 'rietveld.server'],), ''), | |
556 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | 559 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), |
557 ((['git', 'config', 'branch.master.rietveldissue'],), ''), | |
558 ((['git', 'config', 'branch.master.gerritissue'],), ''), | |
559 ((['git', 'config', 'gerrit.host'],), 'True'), | |
560 ((['git', 'config', 'branch.master.merge'],), 'master'), | 560 ((['git', 'config', 'branch.master.merge'],), 'master'), |
561 ((['git', 'config', 'branch.master.remote'],), 'origin'), | 561 ((['git', 'config', 'branch.master.remote'],), 'origin'), |
562 ((['get_or_create_merge_base', 'master', 'master'],), | 562 ((['get_or_create_merge_base', 'master', 'master'],), |
563 'fake_ancestor_sha'), | 563 'fake_ancestor_sha'), |
| 564 ((['git', 'config', 'gerrit.host'],), 'True'), |
564 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ | 565 ] + cls._git_sanity_checks('fake_ancestor_sha', 'master') + [ |
565 ((['git', 'rev-parse', '--show-cdup'],), ''), | 566 ((['git', 'rev-parse', '--show-cdup'],), ''), |
566 ((['git', 'rev-parse', 'HEAD'],), '12345'), | 567 ((['git', 'rev-parse', 'HEAD'],), '12345'), |
567 ((['git', | 568 ((['git', |
568 'diff', '--name-status', '--no-renames', '-r', | 569 'diff', '--name-status', '--no-renames', '-r', |
569 'fake_ancestor_sha...', '.'],), | 570 'fake_ancestor_sha...', '.'],), |
570 'M\t.gitignore\n'), | 571 'M\t.gitignore\n'), |
571 ((['git', 'config', 'branch.master.gerritpatchset'],), ''), | 572 ((['git', 'config', 'branch.master.rietveldissue'],), ''), |
| 573 ((['git', |
| 574 'config', 'branch.master.rietveldpatchset'],), ''), |
572 ((['git', | 575 ((['git', |
573 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), | 576 'log', '--pretty=format:%s%n%n%b', 'fake_ancestor_sha...'],), |
574 'foo'), | 577 'foo'), |
575 ((['git', 'config', 'user.email'],), 'me@example.com'), | 578 ((['git', 'config', 'user.email'],), 'me@example.com'), |
576 ((['git', | 579 ((['git', |
577 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 580 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
578 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 581 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
579 '+dat'), | 582 '+dat'), |
580 ] | 583 ] |
581 | 584 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 'remote: Processing changes: new: 1, done\n' | 655 'remote: Processing changes: new: 1, done\n' |
653 'remote:\n' | 656 'remote:\n' |
654 'remote: New Changes:\n' | 657 'remote: New Changes:\n' |
655 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' | 658 'remote: https://chromium-review.googlesource.com/123456 XXX.\n' |
656 'remote:\n' | 659 'remote:\n' |
657 'To https://chromium.googlesource.com/yyy/zzz\n' | 660 'To https://chromium.googlesource.com/yyy/zzz\n' |
658 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), | 661 ' * [new branch] hhhh -> refs/for/refs/heads/master\n')), |
659 ] | 662 ] |
660 if squash: | 663 if squash: |
661 calls += [ | 664 calls += [ |
662 ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''), | 665 ((['git', 'config', 'branch.master.rietveldissue', '123456'],), ''), |
663 ((['git', 'config', 'branch.master.gerritserver'],), ''), | |
664 ((['git', 'config', 'remote.origin.url'],), | |
665 'https://chromium.googlesource.com/my/repo.git'), | |
666 ((['git', 'config', 'branch.master.gerritserver', | |
667 'https://chromium-review.googlesource.com'],), ''), | |
668 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), | 666 ((['git', 'rev-parse', 'HEAD'],), 'abcdef0123456789'), |
669 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', | 667 ((['git', 'update-ref', '-m', 'Uploaded abcdef0123456789', |
670 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), | 668 'refs/heads/git_cl_uploads/master', 'abcdef0123456789'],), |
671 '') | 669 '') |
672 ] | 670 ] |
673 calls += cls._git_post_upload_calls() | 671 calls += cls._git_post_upload_calls() |
674 return calls | 672 return calls |
675 | 673 |
676 def _run_gerrit_upload_test( | 674 def _run_gerrit_upload_test( |
677 self, | 675 self, |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 # Patch when local tree is dirty | 879 # Patch when local tree is dirty |
882 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) | 880 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
883 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 881 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
884 | 882 |
885 def test_diff_when_dirty(self): | 883 def test_diff_when_dirty(self): |
886 # Do 'git cl diff' when local tree is dirty | 884 # Do 'git cl diff' when local tree is dirty |
887 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) | 885 self.mock(git_common, 'is_dirty_git_tree', lambda x: True) |
888 self.assertNotEqual(git_cl.main(['diff']), 0) | 886 self.assertNotEqual(git_cl.main(['diff']), 0) |
889 | 887 |
890 def _patch_common(self): | 888 def _patch_common(self): |
891 self.mock(git_cl._RietveldChangelistImpl, 'GetMostRecentPatchset', | 889 self.mock(git_cl.Changelist, 'GetMostRecentPatchset', lambda x: '60001') |
892 lambda x: '60001') | 890 self.mock(git_cl.Changelist, 'GetPatchSetDiff', lambda *args: None) |
893 self.mock(git_cl._RietveldChangelistImpl, 'GetPatchSetDiff', | 891 self.mock(git_cl.Changelist, 'GetDescription', lambda *args: 'Description') |
894 lambda *args: None) | |
895 self.mock(git_cl.Changelist, 'GetDescription', | |
896 lambda *args: 'Description') | |
897 self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None) | 892 self.mock(git_cl.Changelist, 'SetIssue', lambda *args: None) |
898 self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None) | 893 self.mock(git_cl.Changelist, 'SetPatchset', lambda *args: None) |
899 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) | 894 self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True) |
900 | 895 |
901 self.calls = [ | 896 self.calls = [ |
902 ((['git', 'config', 'rietveld.autoupdate'],), ''), | 897 ((['git', 'config', 'rietveld.autoupdate'],), ''), |
903 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), | 898 ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'), |
904 ((['git', 'rev-parse', '--show-cdup'],), ''), | 899 ((['git', 'rev-parse', '--show-cdup'],), ''), |
905 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), | 900 ((['sed', '-e', 's|^--- a/|--- |; s|^+++ b/|+++ |'],), ''), |
906 ] | 901 ] |
907 | 902 |
908 def test_patch_successful(self): | 903 def test_patch_successful(self): |
909 self._patch_common() | 904 self._patch_common() |
910 self.calls += [ | 905 self.calls += [ |
911 ((['git', 'apply', '--index', '-p0', '--3way'],), ''), | 906 ((['git', 'apply', '--index', '-p0', '--3way'],), ''), |
912 ((['git', 'commit', '-m', | 907 ((['git', 'commit', '-m', |
913 'Description\n\n' + | 908 'Description\n\n' + |
914 'patch from issue 123456 at patchset 60001 ' + | 909 'patch from issue 123456 at patchset 60001 ' + |
915 '(http://crrev.com/123456#ps60001)'],), ''), | 910 '(http://crrev.com/123456#ps60001)'],), ''), |
916 ((['git', 'symbolic-ref', 'HEAD'],), 'master'), | |
917 ((['git', 'config', 'branch.master.rietveldserver'],), ''), | |
918 ] | 911 ] |
919 self.assertEqual(git_cl.main(['patch', '123456']), 0) | 912 self.assertEqual(git_cl.main(['patch', '123456']), 0) |
920 | 913 |
921 def test_patch_conflict(self): | 914 def test_patch_conflict(self): |
922 self._patch_common() | 915 self._patch_common() |
923 self.calls += [ | 916 self.calls += [ |
924 ((['git', 'apply', '--index', '-p0', '--3way'],), '', | 917 ((['git', 'apply', '--index', '-p0', '--3way'],), '', |
925 subprocess2.CalledProcessError(1, '', '', '', '')), | 918 subprocess2.CalledProcessError(1, '', '', '', '')), |
926 ] | 919 ] |
927 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) | 920 self.assertNotEqual(git_cl.main(['patch', '123456']), 0) |
928 | 921 |
929 if __name__ == '__main__': | 922 if __name__ == '__main__': |
930 git_cl.logging.basicConfig( | 923 git_cl.logging.basicConfig( |
931 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 924 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
932 unittest.main() | 925 unittest.main() |
OLD | NEW |