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