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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 ]) + [ | 750 ]) + [ |
751 ((['git', 'config', 'user.email'],), 'me@example.com'), | 751 ((['git', 'config', 'user.email'],), 'me@example.com'), |
752 ((['git', | 752 ((['git', |
753 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', | 753 'diff', '--no-ext-diff', '--stat', '--find-copies-harder', |
754 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), | 754 '-l100000', '-C50', 'fake_ancestor_sha', 'HEAD'],), |
755 '+dat'), | 755 '+dat'), |
756 ] | 756 ] |
757 | 757 |
758 @classmethod | 758 @classmethod |
759 def _gerrit_upload_calls(cls, description, reviewers, squash, | 759 def _gerrit_upload_calls(cls, description, reviewers, squash, |
| 760 squash_mode='default', |
760 expected_upstream_ref='origin/refs/heads/master', | 761 expected_upstream_ref='origin/refs/heads/master', |
761 ref_suffix='', notify=False, | 762 ref_suffix='', notify=False, |
762 post_amend_description=None, issue=None): | 763 post_amend_description=None, issue=None): |
763 if post_amend_description is None: | 764 if post_amend_description is None: |
764 post_amend_description = description | 765 post_amend_description = description |
| 766 calls = [] |
765 | 767 |
766 calls = [ | 768 # TODO(tandrii): remove duplication here once warning message is removed. |
767 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'), | 769 # see http://crbug.com/611892 |
768 ] | 770 if squash_mode == 'default': |
| 771 calls.extend([ |
| 772 ((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), ''), |
| 773 ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), ''), |
| 774 ((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), ''), |
| 775 ]) |
| 776 elif squash_mode in ('override_squash', 'override_nosquash'): |
| 777 calls.extend([ |
| 778 ((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), |
| 779 'true' if squash_mode == 'override_squash' else 'false'), |
| 780 ((['git', 'config', '--bool', 'gerrit.override-squash-uploads'],), |
| 781 'true' if squash_mode == 'override_squash' else 'false'), |
| 782 ]) |
| 783 else: |
| 784 assert squash_mode in ('squash', 'nosquash') |
| 785 |
769 # If issue is given, then description is fetched from Gerrit instead. | 786 # If issue is given, then description is fetched from Gerrit instead. |
770 if issue is None: | 787 if issue is None: |
771 if squash: | 788 if squash: |
772 calls += [ | 789 calls += [ |
773 ((['git', 'show', '--format=%B', '-s', | 790 ((['git', 'show', '--format=%B', '-s', |
774 'refs/heads/git_cl_uploads/master'],), '')] | 791 'refs/heads/git_cl_uploads/master'],), '')] |
775 calls += [ | 792 calls += [ |
776 ((['git', 'log', '--pretty=format:%s\n\n%b', | 793 ((['git', 'log', '--pretty=format:%s\n\n%b', |
777 'fake_ancestor_sha..HEAD'],), | 794 'fake_ancestor_sha..HEAD'],), |
778 description)] | 795 description)] |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 ] | 878 ] |
862 calls += cls._git_post_upload_calls() | 879 calls += cls._git_post_upload_calls() |
863 return calls | 880 return calls |
864 | 881 |
865 def _run_gerrit_upload_test( | 882 def _run_gerrit_upload_test( |
866 self, | 883 self, |
867 upload_args, | 884 upload_args, |
868 description, | 885 description, |
869 reviewers=None, | 886 reviewers=None, |
870 squash=False, | 887 squash=False, |
| 888 squash_mode=None, |
871 expected_upstream_ref='origin/refs/heads/master', | 889 expected_upstream_ref='origin/refs/heads/master', |
872 ref_suffix='', | 890 ref_suffix='', |
873 notify=False, | 891 notify=False, |
874 post_amend_description=None, | 892 post_amend_description=None, |
875 issue=None): | 893 issue=None): |
876 """Generic gerrit upload test framework.""" | 894 """Generic gerrit upload test framework.""" |
| 895 if squash_mode is None: |
| 896 if '--no-squash' in upload_args: |
| 897 squash_mode = 'nosquash' |
| 898 elif '--squash' in upload_args: |
| 899 squash_mode = 'squash' |
| 900 else: |
| 901 squash_mode = 'default' |
| 902 |
877 reviewers = reviewers or [] | 903 reviewers = reviewers or [] |
878 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) | 904 self.mock(git_cl.sys, 'stdout', StringIO.StringIO()) |
879 self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', | 905 self.mock(git_cl.gerrit_util, 'CookiesAuthenticator', |
880 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) | 906 CookiesAuthenticatorMockFactory(same_cookie='same_cred')) |
881 self.mock(git_cl._GerritChangelistImpl, '_GerritCommitMsgHookCheck', | 907 self.mock(git_cl._GerritChangelistImpl, '_GerritCommitMsgHookCheck', |
882 lambda _, offer_removal: None) | 908 lambda _, offer_removal: None) |
883 self.calls = self._gerrit_base_calls(issue=issue) | 909 self.calls = self._gerrit_base_calls(issue=issue) |
884 self.calls += self._gerrit_upload_calls( | 910 self.calls += self._gerrit_upload_calls( |
885 description, reviewers, squash, | 911 description, reviewers, squash, |
| 912 squash_mode=squash_mode, |
886 expected_upstream_ref=expected_upstream_ref, | 913 expected_upstream_ref=expected_upstream_ref, |
887 ref_suffix=ref_suffix, notify=notify, | 914 ref_suffix=ref_suffix, notify=notify, |
888 post_amend_description=post_amend_description, | 915 post_amend_description=post_amend_description, |
889 issue=issue) | 916 issue=issue) |
890 # Uncomment when debugging. | 917 # Uncomment when debugging. |
891 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) | 918 # print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls))) |
892 git_cl.main(['upload'] + upload_args) | 919 git_cl.main(['upload'] + upload_args) |
893 | 920 |
894 def test_gerrit_upload_without_change_id(self): | 921 def test_gerrit_upload_without_change_id(self): |
895 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) | 922 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) |
896 self._run_gerrit_upload_test( | 923 self._run_gerrit_upload_test( |
897 [], | 924 [], |
898 'desc\n\nBUG=\n', | 925 'desc\n\nBUG=\n', |
899 [], | 926 [], |
900 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') | 927 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') |
901 | 928 |
| 929 def test_gerrit_upload_without_change_id_override_nosquash(self): |
| 930 self.mock(git_cl, 'DownloadGerritHook', self._mocked_call) |
| 931 self._run_gerrit_upload_test( |
| 932 [], |
| 933 'desc\n\nBUG=\n', |
| 934 [], |
| 935 squash_mode='override_nosquash', |
| 936 post_amend_description='desc\n\nBUG=\n\nChange-Id: Ixxx') |
| 937 |
902 def test_gerrit_no_reviewer(self): | 938 def test_gerrit_no_reviewer(self): |
903 self._run_gerrit_upload_test( | 939 self._run_gerrit_upload_test( |
904 [], | 940 [], |
905 'desc\n\nBUG=\n\nChange-Id: I123456789\n', | 941 'desc\n\nBUG=\n\nChange-Id: I123456789\n', |
906 []) | 942 []) |
907 | 943 |
908 def test_gerrit_patch_title(self): | 944 def test_gerrit_patch_title(self): |
909 self._run_gerrit_upload_test( | 945 self._run_gerrit_upload_test( |
910 ['-t', 'Don\'t put under_scores as they become spaces'], | 946 ['-t', 'Don\'t put under_scores as they become spaces'], |
911 'desc\n\nBUG=\n\nChange-Id: I123456789', | 947 'desc\n\nBUG=\n\nChange-Id: I123456789', |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), | 1664 ((['rm_file_or_tree', '/abs/git_repo_root/.git/hooks/commit-msg'],), |
1629 ''), | 1665 ''), |
1630 ] | 1666 ] |
1631 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) | 1667 cl._codereview_impl._GerritCommitMsgHookCheck(offer_removal=True) |
1632 | 1668 |
1633 | 1669 |
1634 if __name__ == '__main__': | 1670 if __name__ == '__main__': |
1635 git_cl.logging.basicConfig( | 1671 git_cl.logging.basicConfig( |
1636 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) | 1672 level=git_cl.logging.DEBUG if '-v' in sys.argv else git_cl.logging.ERROR) |
1637 unittest.main() | 1673 unittest.main() |
OLD | NEW |