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 contextlib | 8 import contextlib |
9 import json | 9 import json |
10 import os | 10 import os |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 private_call = [] | 602 private_call = [] |
603 else: | 603 else: |
604 cc_call = [((['git', 'config', 'rietveld.cc'],), '')] | 604 cc_call = [((['git', 'config', 'rietveld.cc'],), '')] |
605 private_call = [ | 605 private_call = [ |
606 ((['git', 'config', 'rietveld.private'],), '')] | 606 ((['git', 'config', 'rietveld.private'],), '')] |
607 | 607 |
608 return [ | 608 return [ |
609 ((['git', 'config', 'core.editor'],), ''), | 609 ((['git', 'config', 'core.editor'],), ''), |
610 ] + cc_call + private_call + [ | 610 ] + cc_call + private_call + [ |
611 ((['git', 'config', 'branch.master.base-url'],), ''), | 611 ((['git', 'config', 'branch.master.base-url'],), ''), |
612 ((['git', 'config', 'rietveld.pending-ref-prefix'],), ''), | 612 ((['git', 'config', 'remote.origin.url'],), ''), |
613 ((['git', | |
614 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | |
615 (('', None), 0)), | |
616 ((['git', 'rev-parse', '--show-cdup'],), ''), | |
617 ((['git', 'svn', 'info'],), ''), | |
618 ((['git', 'config', 'rietveld.project'],), ''), | 613 ((['git', 'config', 'rietveld.project'],), ''), |
619 ((['git', 'config', 'branch.master.rietveldissue', '1'],), ''), | 614 ((['git', 'config', 'branch.master.rietveldissue', '1'],), ''), |
620 ((['git', 'config', 'branch.master.rietveldserver', | 615 ((['git', 'config', 'branch.master.rietveldserver', |
621 'https://codereview.example.com'],), ''), | 616 'https://codereview.example.com'],), ''), |
622 ((['git', | 617 ((['git', |
623 'config', 'branch.master.rietveldpatchset', '2'],), ''), | 618 'config', 'branch.master.rietveldpatchset', '2'],), ''), |
624 ] + cls._git_post_upload_calls() | 619 ] + cls._git_post_upload_calls() |
625 | 620 |
626 @classmethod | 621 @classmethod |
627 def _git_post_upload_calls(cls): | 622 def _git_post_upload_calls(cls): |
(...skipping 24 matching lines...) Expand all Loading... |
652 ((['git', | 647 ((['git', |
653 'config', 'branch.%s.merge' % working_branch],), | 648 'config', 'branch.%s.merge' % working_branch],), |
654 'refs/heads/master'), | 649 'refs/heads/master'), |
655 ((['git', | 650 ((['git', |
656 'config', 'branch.%s.remote' % working_branch],), 'origin'), | 651 'config', 'branch.%s.remote' % working_branch],), 'origin'), |
657 ] if get_remote_branch else []) + [ | 652 ] if get_remote_branch else []) + [ |
658 ((['git', 'rev-list', '^' + fake_ancestor, | 653 ((['git', 'rev-list', '^' + fake_ancestor, |
659 'refs/remotes/origin/master'],), ''), | 654 'refs/remotes/origin/master'],), ''), |
660 ] | 655 ] |
661 | 656 |
662 @classmethod | |
663 def _dcommit_calls_1(cls): | |
664 return [ | |
665 ((['git', 'config', 'rietveld.autoupdate'],), | |
666 ''), | |
667 ((['git', 'config', 'rietveld.pending-ref-prefix'],), | |
668 ''), | |
669 ((['git', | |
670 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | |
671 ((('svn-remote.svn.url svn://svn.chromium.org/chrome\n' | |
672 'svn-remote.svn.fetch trunk/src:refs/remotes/origin/master'), | |
673 None), | |
674 0)), | |
675 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | |
676 ((['git', 'config', | |
677 'branch.working.git-cl-similarity'],), CERR1), | |
678 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | |
679 ((['git', 'config', '--bool', | |
680 'branch.working.git-find-copies'],), CERR1), | |
681 ((['git', 'symbolic-ref', 'HEAD'],), 'refs/heads/working'), | |
682 ((['git', | |
683 'config', 'branch.working.rietveldissue'],), '12345'), | |
684 ((['git', | |
685 'config', 'rietveld.server'],), 'codereview.example.com'), | |
686 ((['git', | |
687 'config', 'branch.working.merge'],), 'refs/heads/master'), | |
688 ((['git', 'config', 'branch.working.remote'],), 'origin'), | |
689 ((['git', 'config', 'branch.working.merge'],), | |
690 'refs/heads/master'), | |
691 ((['git', 'config', 'branch.working.remote'],), 'origin'), | |
692 ((['git', 'rev-list', '--merges', | |
693 '--grep=^SVN changes up to revision [0-9]*$', | |
694 'refs/remotes/origin/master^!'],), ''), | |
695 ((['git', 'rev-list', '^refs/heads/working', | |
696 'refs/remotes/origin/master'],), | |
697 ''), | |
698 ((['git', | |
699 'log', '--grep=^git-svn-id:', '-1', '--pretty=format:%H'],), | |
700 '3fc18b62c4966193eb435baabe2d18a3810ec82e'), | |
701 ((['git', | |
702 'rev-list', '^3fc18b62c4966193eb435baabe2d18a3810ec82e', | |
703 'refs/remotes/origin/master'],), ''), | |
704 ((['git', | |
705 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), | |
706 'fake_ancestor_sha'), | |
707 ] | |
708 | |
709 @classmethod | |
710 def _dcommit_calls_normal(cls): | |
711 return [ | |
712 ((['git', 'rev-parse', '--show-cdup'],), ''), | |
713 ((['git', 'rev-parse', 'HEAD'],), | |
714 '00ff397798ea57439712ed7e04ab96e13969ef40'), | |
715 ((['git', | |
716 'diff', '--name-status', '--no-renames', '-r', 'fake_ancestor_sha...', | |
717 '.'],), | |
718 'M\tPRESUBMIT.py'), | |
719 ((['git', | |
720 'config', 'branch.working.rietveldpatchset'],), '31137'), | |
721 ((['git', 'config', 'branch.working.rietveldserver'],), | |
722 'codereview.example.com'), | |
723 ((['git', 'config', 'user.email'],), 'author@example.com'), | |
724 ((['git', 'config', 'rietveld.tree-status-url'],), ''), | |
725 ] | |
726 | |
727 @classmethod | |
728 def _dcommit_calls_bypassed(cls): | |
729 return [ | |
730 ((['git', 'config', 'branch.working.rietveldserver'],), | |
731 'codereview.example.com'), | |
732 ] | |
733 | |
734 @classmethod | |
735 def _dcommit_calls_3(cls): | |
736 return [ | |
737 ((['git', | |
738 'diff', '--no-ext-diff', '--stat', '-l100000', '-C50', | |
739 'fake_ancestor_sha', 'refs/heads/working'],), | |
740 (' PRESUBMIT.py | 2 +-\n' | |
741 ' 1 files changed, 1 insertions(+), 1 deletions(-)\n')), | |
742 ((['git', 'show-ref', '--quiet', '--verify', | |
743 'refs/heads/git-cl-commit'],), ''), | |
744 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
745 ((['git', 'show-ref', '--quiet', '--verify', | |
746 'refs/heads/git-cl-cherry-pick'],), CERR1), | |
747 ((['git', 'rev-parse', '--show-cdup'],), '\n'), | |
748 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), | |
749 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), | |
750 ((['git', 'commit', '-m', | |
751 'Issue: 12345\n\nR=john@chromium.org\n\n' | |
752 'Review-Url: https://codereview.example.com/12345 .'],), | |
753 ''), | |
754 ((['git', 'config', 'rietveld.force-https-commit-url'],), ''), | |
755 ((['git', | |
756 'svn', 'dcommit', '-C50', '--no-rebase', '--rmdir'],), | |
757 (('', None), 0)), | |
758 ((['git', 'checkout', '-q', 'working'],), ''), | |
759 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
760 ] | |
761 | |
762 @staticmethod | 657 @staticmethod |
763 def _cmd_line(description, args, similarity, find_copies, private, cc): | 658 def _cmd_line(description, args, similarity, find_copies, private, cc): |
764 """Returns the upload command line passed to upload.RealMain().""" | 659 """Returns the upload command line passed to upload.RealMain().""" |
765 return [ | 660 return [ |
766 'upload', '--assume_yes', '--server', | 661 'upload', '--assume_yes', '--server', |
767 'https://codereview.example.com', | 662 'https://codereview.example.com', |
768 '--message', description | 663 '--message', description |
769 ] + args + [ | 664 ] + args + [ |
770 '--cc', ','.join(['joe@example.com'] + cc), | 665 '--cc', ','.join(['joe@example.com'] + cc), |
771 ] + (['--private'] if private else []) + [ | 666 ] + (['--private'] if private else []) + [ |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 stdout.getvalue()) | 814 stdout.getvalue()) |
920 | 815 |
921 def test_bug_on_cmd(self): | 816 def test_bug_on_cmd(self): |
922 self._run_reviewer_test( | 817 self._run_reviewer_test( |
923 ['--bug=500658,proj:123'], | 818 ['--bug=500658,proj:123'], |
924 'desc\n\nBUG=500658\nBUG=proj:123', | 819 'desc\n\nBUG=500658\nBUG=proj:123', |
925 '# Blah blah comment.\ndesc\n\nBUG=500658\nBUG=proj:1234', | 820 '# Blah blah comment.\ndesc\n\nBUG=500658\nBUG=proj:1234', |
926 'desc\n\nBUG=500658\nBUG=proj:1234', | 821 'desc\n\nBUG=500658\nBUG=proj:1234', |
927 []) | 822 []) |
928 | 823 |
929 def test_dcommit(self): | |
930 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
931 self.calls = ( | |
932 self._dcommit_calls_1() + | |
933 self._git_sanity_checks('fake_ancestor_sha', 'working') + | |
934 self._dcommit_calls_normal() + | |
935 self._dcommit_calls_3()) | |
936 git_cl.main(['dcommit']) | |
937 | |
938 def test_dcommit_bypass_hooks(self): | |
939 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
940 self.calls = ( | |
941 self._dcommit_calls_1() + | |
942 self._dcommit_calls_bypassed() + | |
943 self._dcommit_calls_3()) | |
944 git_cl.main(['dcommit', '--bypass-hooks']) | |
945 | |
946 def _land_rietveld_common(self, debug=False): | |
947 if debug: | |
948 # Very useful due to finally clause in git cl land raising exceptions and | |
949 # shadowing real cause of failure. | |
950 self.mock(git_cl, '_IS_BEING_TESTED', True) | |
951 else: | |
952 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
953 | |
954 self.mock(git_cl._GitNumbererState, 'load', classmethod(lambda _, url, ref: | |
955 self._mocked_call(['_GitNumbererState', url, ref]))) | |
956 self.mock(RietveldMock, 'update_description', staticmethod( | |
957 lambda i, d: self._mocked_call(['update_description', i, d]))) | |
958 self.mock(RietveldMock, 'add_comment', staticmethod( | |
959 lambda i, c: self._mocked_call(['add_comment', i, c]))) | |
960 self.calls = [ | |
961 ((['git', 'config', 'rietveld.autoupdate'],), ''), | |
962 ((['git', 'config', 'rietveld.pending-ref-prefix'],), CERR1), | |
963 ((['git', 'config', '--local', '--get-regexp', '^svn-remote\\.'],), | |
964 CERR1), | |
965 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | |
966 ((['git', 'config', 'branch.feature.git-cl-similarity'],), CERR1), | |
967 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | |
968 ((['git', 'config', '--bool', 'branch.feature.git-find-copies'],), | |
969 CERR1), | |
970 ((['git', 'symbolic-ref', 'HEAD'],), 'feature'), | |
971 ((['git', 'config', 'branch.feature.rietveldissue'],), '123'), | |
972 ((['git', 'config', 'rietveld.server'],), | |
973 'https://codereview.chromium.org'), | |
974 ((['git', 'config', 'branch.feature.merge'],), 'refs/heads/master'), | |
975 ((['git', 'config', 'branch.feature.remote'],), 'origin'), | |
976 ((['git', 'config', 'branch.feature.merge'],), 'refs/heads/master'), | |
977 ((['git', 'config', 'branch.feature.remote'],), 'origin'), | |
978 ((['git', 'rev-list', '--merges', | |
979 '--grep=^SVN changes up to revision [0-9]*$', | |
980 'refs/remotes/origin/master^!'],), ''), | |
981 ((['git', 'rev-list', '^feature', 'refs/remotes/origin/master'],), | |
982 ''), # No commits to rebase, according to local view of origin. | |
983 ((['git', 'merge-base', 'refs/remotes/origin/master', 'HEAD'],), | |
984 'fake_ancestor_sha'), | |
985 ] + self._git_sanity_checks('fake_ancestor_sha', 'feature') + [ | |
986 ((['git', 'rev-parse', '--show-cdup'],), ''), | |
987 ((['git', 'rev-parse', 'HEAD'],), 'fake_sha'), | |
988 ((['git', 'diff', '--name-status', '--no-renames', '-r', | |
989 'fake_ancestor_sha...', '.'],), | |
990 'M\tfile1.cpp'), | |
991 ((['git', 'config', 'branch.feature.rietveldpatchset'],), '20001'), | |
992 ((['git', 'config', 'branch.feature.rietveldserver'],), | |
993 'https://codereview.chromium.org'), | |
994 ((['git', 'config', 'user.email'],), 'user@e.mail'), | |
995 ((['git', 'config', 'rietveld.tree-status-url'],), CERR1), | |
996 ((['git', 'diff', '--no-ext-diff', '--stat', '-l100000', '-C50', | |
997 'fake_ancestor_sha', 'feature'],), | |
998 # This command just prints smth like this: | |
999 # file1.cpp | 53 ++++++-- | |
1000 # 1 file changed, 33 insertions(+), 20 deletions(-)\n | |
1001 ''), | |
1002 ((['git', 'show-ref', '--quiet', '--verify', | |
1003 'refs/heads/git-cl-commit'],), | |
1004 ''), # 0 return code means branch exists. | |
1005 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
1006 ((['git', 'show-ref', '--quiet', '--verify', | |
1007 'refs/heads/git-cl-cherry-pick'],), | |
1008 CERR1), # This means git-cl-cherry-pick branch does not exist. | |
1009 ((['git', 'rev-parse', '--show-cdup'],), ''), | |
1010 ((['git', 'checkout', '-q', '-b', 'git-cl-commit'],), ''), | |
1011 ((['git', 'reset', '--soft', 'fake_ancestor_sha'],), ''), | |
1012 ((['git', 'commit', '-m', | |
1013 'Issue: 123\n\nR=john@chromium.org\n\n' | |
1014 'Review-Url: https://codereview.chromium.org/123 .'],), ''), | |
1015 ((['git', 'config', 'branch.feature.merge'],), 'refs/heads/master'), | |
1016 ((['git', 'config', 'branch.feature.remote'],), 'origin'), | |
1017 ((['git', 'config', '--get', 'remote.origin.url'],), | |
1018 'https://chromium.googlesource.com/infra/infra'), | |
1019 ] | |
1020 | |
1021 def test_land_rietveld(self): | |
1022 self._land_rietveld_common(debug=False) | |
1023 self.calls += [ | |
1024 ((['git', 'config', 'remote.origin.url'],), | |
1025 'https://chromium.googlesource.com/infra/infra'), | |
1026 ((['_GitNumbererState', | |
1027 'https://chromium.googlesource.com/infra/infra', | |
1028 'refs/heads/master'],), | |
1029 git_cl._GitNumbererState(None, False)), | |
1030 ((['git', 'push', '--porcelain', 'origin', 'HEAD:refs/heads/master'],), | |
1031 ''), | |
1032 ((['git', 'rev-parse', 'HEAD'],), 'fake_sha_rebased'), | |
1033 ((['git', 'checkout', '-q', 'feature'],), ''), | |
1034 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
1035 ((['git', 'config', 'rietveld.viewvc-url'],), | |
1036 'https://chromium.googlesource.com/infra/infra/+/'), | |
1037 ((['update_description', 123, | |
1038 'Issue: 123\n\nR=john@chromium.org\n\nCommitted: ' | |
1039 'https://chromium.googlesource.com/infra/infra/+/fake_sha_rebased'],), | |
1040 ''), | |
1041 ((['add_comment', 123, 'Committed patchset #2 (id:20001) manually as ' | |
1042 'fake_sha_rebased (presubmit successful).'],), ''), | |
1043 ] | |
1044 git_cl.main(['land']) | |
1045 | |
1046 def test_land_rietveld_gnumbd(self): | |
1047 self._land_rietveld_common(debug=False) | |
1048 self.mock(git_cl, 'WaitForRealCommit', | |
1049 lambda *a: self._mocked_call(['WaitForRealCommit'] + list(a))) | |
1050 self.calls += [ | |
1051 ((['git', 'config', 'remote.origin.url'],), | |
1052 'https://chromium.googlesource.com/chromium/src'), | |
1053 ((['_GitNumbererState', | |
1054 'https://chromium.googlesource.com/chromium/src', | |
1055 'refs/heads/master'],), | |
1056 git_cl._GitNumbererState('refs/pending', True)), | |
1057 ((['git', 'rev-parse', 'HEAD'],), 'fake_sha_rebased'), | |
1058 ((['git', 'retry', 'fetch', 'origin', | |
1059 '+refs/pending/heads/master:refs/git-cl/pending/heads/master'],), ''), | |
1060 ((['git', 'checkout', 'refs/git-cl/pending/heads/master'],), ''), | |
1061 ((['git', 'cherry-pick', 'fake_sha_rebased'],), ''), | |
1062 | |
1063 ((['git', 'retry', 'push', '--porcelain', 'origin', | |
1064 'HEAD:refs/pending/heads/master'],),''), | |
1065 ((['git', 'rev-parse', 'HEAD'],), 'fake_sha_rebased_on_pending'), | |
1066 | |
1067 ((['git', 'checkout', '-q', 'feature'],), ''), | |
1068 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
1069 | |
1070 ((['WaitForRealCommit', 'origin', 'fake_sha_rebased_on_pending', | |
1071 'refs/remotes/origin/master', 'refs/heads/master'],), | |
1072 'fake_sha_gnumbded'), | |
1073 | |
1074 ((['git', 'config', 'rietveld.viewvc-url'],), | |
1075 'https://chromium.googlesource.com/infra/infra/+/'), | |
1076 ((['update_description', 123, | |
1077 'Issue: 123\n\nR=john@chromium.org\n\nCommitted: ' | |
1078 'https://chromium.googlesource.com/infra/infra/+/fake_sha_gnumbded'],), | |
1079 ''), | |
1080 ((['add_comment', 123, 'Committed patchset #2 (id:20001) manually as ' | |
1081 'fake_sha_gnumbded (presubmit successful).'],), | |
1082 ''), | |
1083 ] | |
1084 git_cl.main(['land']) | |
1085 | |
1086 def test_land_rietveld_git_numberer(self): | |
1087 self._land_rietveld_common(debug=False) | |
1088 | |
1089 # Special mocks to check validity of timestamp. | |
1090 original_git_amend_head = git_cl._git_amend_head | |
1091 def _git_amend_head_mock(msg, tstamp): | |
1092 self._mocked_call(['git_amend_head committer timestamp', tstamp]) | |
1093 return original_git_amend_head(msg, tstamp) | |
1094 self.mock(git_cl, '_git_amend_head', _git_amend_head_mock) | |
1095 | |
1096 self.calls += [ | |
1097 ((['git', 'config', 'remote.origin.url'],), | |
1098 'https://chromium.googlesource.com/chromium/src'), | |
1099 ((['_GitNumbererState', | |
1100 'https://chromium.googlesource.com/chromium/src', | |
1101 'refs/heads/master'],), | |
1102 git_cl._GitNumbererState(None, True)), | |
1103 | |
1104 ((['git', 'show', '-s', '--format=%B', 'fake_ancestor_sha'],), | |
1105 'This is parent commit.\n' | |
1106 '\n' | |
1107 'Cr-Commit-Position: refs/heads/master@{#543}\n' | |
1108 'Cr-Branched-From: refs/svn/2014@{#2208}'), | |
1109 ((['git', 'show', '-s', '--format=%ct', 'fake_ancestor_sha'],), | |
1110 '1480022355'), # Committer's unix timestamp. | |
1111 ((['git', 'show', '-s', '--format=%ct', 'HEAD'],), | |
1112 '1480024000'), | |
1113 | |
1114 ((['git_amend_head committer timestamp', 1480024000],), None), | |
1115 ((['git', 'commit', '--amend', '-m', | |
1116 'Issue: 123\n\nR=john@chromium.org\n' | |
1117 '\n' | |
1118 'Review-Url: https://codereview.chromium.org/123 .\n' | |
1119 'Cr-Commit-Position: refs/heads/master@{#544}\n' | |
1120 'Cr-Branched-From: refs/svn/2014@{#2208}'],), ''), | |
1121 | |
1122 ((['git', 'push', '--porcelain', 'origin', 'HEAD:refs/heads/master'],), | |
1123 ''), | |
1124 ((['git', 'rev-parse', 'HEAD'],), 'fake_sha_rebased'), | |
1125 ((['git', 'checkout', '-q', 'feature'],), ''), | |
1126 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
1127 ((['git', 'config', 'rietveld.viewvc-url'],), | |
1128 'https://chromium.googlesource.com/infra/infra/+/'), | |
1129 ((['update_description', 123, | |
1130 'Issue: 123\n\nR=john@chromium.org\n' | |
1131 '\n' | |
1132 'Review-Url: https://codereview.chromium.org/123 .\n' | |
1133 'Cr-Commit-Position: refs/heads/master@{#544}\n' | |
1134 'Cr-Branched-From: refs/svn/2014@{#2208}\n' | |
1135 'Committed: ' | |
1136 'https://chromium.googlesource.com/infra/infra/+/fake_sha_rebased'],), | |
1137 ''), | |
1138 ((['add_comment', 123, 'Committed patchset #2 (id:20001) manually as ' | |
1139 'fake_sha_rebased (presubmit successful).'],), ''), | |
1140 ] | |
1141 git_cl.main(['land']) | |
1142 | |
1143 def test_land_rietveld_git_numberer_bad_parent(self): | |
1144 self._land_rietveld_common(debug=False) | |
1145 self.calls += [ | |
1146 ((['git', 'config', 'remote.origin.url'],), | |
1147 'https://chromium.googlesource.com/v8/v8'), | |
1148 ((['_GitNumbererState', | |
1149 'https://chromium.googlesource.com/v8/v8', 'refs/heads/master'],), | |
1150 git_cl._GitNumbererState(None, True)), | |
1151 | |
1152 ((['git', 'show', '-s', '--format=%B', 'fake_ancestor_sha'],), | |
1153 'This is parent commit with no footer.'), | |
1154 | |
1155 ((['git', 'checkout', '-q', 'feature'],), ''), | |
1156 ((['git', 'branch', '-D', 'git-cl-commit'],), ''), | |
1157 ] | |
1158 with self.assertRaises(ValueError) as cm: | |
1159 git_cl.main(['land']) | |
1160 self.assertEqual(cm.exception.message, | |
1161 'Unable to infer commit position from footers') | |
1162 | |
1163 def test_GitNumbererState_not_whitelisted_repo(self): | |
1164 self.calls = [ | |
1165 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), | |
1166 ((['git', 'config', 'rietveld.pending-ref-prefix'],), CERR1), | |
1167 ] | |
1168 res = git_cl._GitNumbererState.load( | |
1169 remote_url='https://chromium.googlesource.com/chromium/tools/build', | |
1170 remote_ref='refs/whatever') | |
1171 self.assertEqual(res.pending_prefix, None) | |
1172 self.assertEqual(res.should_git_number, False) | |
1173 | |
1174 def test_GitNumbererState_fail_fetch(self): | |
1175 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
1176 self.calls = [ | |
1177 ((['git', 'fetch', 'https://chromium.googlesource.com/chromium/src', | |
1178 '+refs/meta/config:refs/git_cl/meta/config', | |
1179 '+refs/gnumbd-config/main:refs/git_cl/gnumbd-config/main'],), CERR1), | |
1180 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), | |
1181 ((['git', 'config', 'rietveld.pending-ref-prefix'],), | |
1182 'refs/pending-prefix'), | |
1183 ] | |
1184 res = git_cl._GitNumbererState.load( | |
1185 remote_url='https://chromium.googlesource.com/chromium/src', | |
1186 remote_ref='refs/whatever') | |
1187 self.assertEqual(res.pending_prefix, 'refs/pending-prefix/') | |
1188 self.assertEqual(res.should_git_number, False) | |
1189 | |
1190 def test_GitNumbererState_fail_gnumbd_and_validator(self): | |
1191 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | |
1192 self.calls = [ | |
1193 ((['git', 'fetch', 'https://chromium.googlesource.com/chromium/src', | |
1194 '+refs/meta/config:refs/git_cl/meta/config', | |
1195 '+refs/gnumbd-config/main:refs/git_cl/gnumbd-config/main'],), ''), | |
1196 ((['git', 'show', 'refs/git_cl/gnumbd-config/main:config.json'],), | |
1197 'ba d conig'), | |
1198 ((['git', 'config', 'rietveld.autoupdate'],), CERR1), | |
1199 ((['git', 'config', 'rietveld.pending-ref-prefix'],), CERR1), | |
1200 ((['git', 'show', 'refs/git_cl/meta/config:project.config'],), CERR1), | |
1201 ] | |
1202 res = git_cl._GitNumbererState.load( | |
1203 remote_url='https://chromium.googlesource.com/chromium/src', | |
1204 remote_ref='refs/whatever') | |
1205 self.assertEqual(res.pending_prefix, None) | |
1206 self.assertEqual(res.should_git_number, False) | |
1207 | |
1208 def test_GitNumbererState_valid_configs(self): | |
1209 class NamedTempFileStab(StringIO.StringIO): | |
1210 @classmethod | |
1211 @contextlib.contextmanager | |
1212 def create(cls, *_, **__): | |
1213 yield cls() | |
1214 name = 'tempfile' | |
1215 self.mock(git_cl.tempfile, 'NamedTemporaryFile', NamedTempFileStab.create) | |
1216 self.calls = [ | |
1217 ((['git', 'fetch', 'https://chromium.googlesource.com/chromium/src', | |
1218 '+refs/meta/config:refs/git_cl/meta/config', | |
1219 '+refs/gnumbd-config/main:refs/git_cl/gnumbd-config/main'],), ''), | |
1220 ((['git', 'show', 'refs/git_cl/gnumbd-config/main:config.json'],), | |
1221 '''{ | |
1222 "pending_tag_prefix": "refs/pending-tags", | |
1223 "pending_ref_prefix": "refs/pending", | |
1224 "enabled_refglobs": [ | |
1225 "refs/heads/m*" | |
1226 ] | |
1227 } | |
1228 '''), | |
1229 ((['git', 'show', 'refs/git_cl/meta/config:project.config'],), | |
1230 ''' | |
1231 [plugin "git-numberer"] | |
1232 validate-enabled-refglob = refs/else/* | |
1233 validate-enabled-refglob = refs/heads/* | |
1234 validate-disabled-refglob = refs/heads/disabled | |
1235 validate-disabled-refglob = refs/branch-heads/* | |
1236 '''), | |
1237 ((['git', 'config', '-f', 'tempfile', '--get-all', | |
1238 'plugin.git-numberer.validate-enabled-refglob'],), | |
1239 'refs/else/*\n' | |
1240 'refs/heads/*\n'), | |
1241 ((['git', 'config', '-f', 'tempfile', '--get-all', | |
1242 'plugin.git-numberer.validate-disabled-refglob'],), | |
1243 'refs/heads/disabled\n' | |
1244 'refs/branch-heads/*\n'), | |
1245 ] * 4 # 4 tests below have exactly same IO. | |
1246 | |
1247 res = git_cl._GitNumbererState.load( | |
1248 remote_url='https://chromium.googlesource.com/chromium/src', | |
1249 remote_ref='refs/heads/master') | |
1250 self.assertEqual(res.pending_prefix, 'refs/pending/') | |
1251 self.assertEqual(res.should_git_number, False) | |
1252 | |
1253 res = git_cl._GitNumbererState.load( | |
1254 remote_url='https://chromium.googlesource.com/chromium/src', | |
1255 remote_ref='refs/heads/test') | |
1256 self.assertEqual(res.pending_prefix, None) | |
1257 self.assertEqual(res.should_git_number, True) | |
1258 | |
1259 res = git_cl._GitNumbererState.load( | |
1260 remote_url='https://chromium.googlesource.com/chromium/src', | |
1261 remote_ref='refs/heads/disabled') | |
1262 self.assertEqual(res.pending_prefix, None) | |
1263 self.assertEqual(res.should_git_number, False) | |
1264 | |
1265 # Validator is disabled by default, even if it's not explicitely in disabled | |
1266 # refglobs. | |
1267 res = git_cl._GitNumbererState.load( | |
1268 remote_url='https://chromium.googlesource.com/chromium/src', | |
1269 remote_ref='refs/arbitrary/ref') | |
1270 self.assertEqual(res.pending_prefix, None) | |
1271 self.assertEqual(res.should_git_number, False) | |
1272 | |
1273 @classmethod | 824 @classmethod |
1274 def _gerrit_ensure_auth_calls(cls, issue=None, skip_auth_check=False): | 825 def _gerrit_ensure_auth_calls(cls, issue=None, skip_auth_check=False): |
1275 cmd = ['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated'] | 826 cmd = ['git', 'config', '--bool', 'gerrit.skip-ensure-authenticated'] |
1276 if skip_auth_check: | 827 if skip_auth_check: |
1277 return [((cmd, ), 'true')] | 828 return [((cmd, ), 'true')] |
1278 | 829 |
1279 calls = [((cmd, ), CERR1)] | 830 calls = [((cmd, ), CERR1)] |
1280 if issue: | 831 if issue: |
1281 calls.extend([ | 832 calls.extend([ |
1282 ((['git', 'config', 'branch.master.gerritserver'],), ''), | 833 ((['git', 'config', 'branch.master.gerritserver'],), ''), |
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2891 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') | 2442 self.assertNotRegexpMatches(sys.stdout.getvalue(), 'Warning') |
2892 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') | 2443 self.assertRegexpMatches(sys.stdout.getvalue(), '^Failures:') |
2893 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') | 2444 self.assertRegexpMatches(sys.stdout.getvalue(), 'Started:') |
2894 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') | 2445 self.assertRegexpMatches(sys.stdout.getvalue(), '2 try jobs') |
2895 | 2446 |
2896 | 2447 |
2897 if __name__ == '__main__': | 2448 if __name__ == '__main__': |
2898 git_cl.logging.basicConfig( | 2449 git_cl.logging.basicConfig( |
2899 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 2450 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
2900 unittest.main() | 2451 unittest.main() |
OLD | NEW |