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

Side by Side Diff: tests/gclient_scm_test.py

Issue 61823002: Merge instead of rebasing upstream changes in `gclient sync` when --merge is given. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: lint fixes Created 6 years, 11 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 | « gclient_scm.py ('k') | no next file » | 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 gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # pylint: disable=E1103 8 # pylint: disable=E1103
9 9
10 # Import before super_mox to keep valid references. 10 # Import before super_mox to keep valid references.
11 from shutil import rmtree 11 from shutil import rmtree
12 from subprocess import Popen, PIPE, STDOUT 12 from subprocess import Popen, PIPE, STDOUT
13 13
14 import logging 14 import logging
15 import os 15 import os
16 import sys 16 import sys
17 import tempfile 17 import tempfile
18 import unittest 18 import unittest
19 import __builtin__
20 19
21 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 20 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
22 21
23 from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase 22 from testing_support.super_mox import mox, StdoutCheck, SuperMoxTestBase
24 from testing_support.super_mox import TestCaseUtils 23 from testing_support.super_mox import TestCaseUtils
25 24
26 import gclient_scm 25 import gclient_scm
27 import subprocess2 26 import subprocess2
28 27
29 # Shortcut since this function is used often 28 # Shortcut since this function is used often
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 commit refs/heads/origin 744 commit refs/heads/origin
746 mark :6 745 mark :6
747 author Alice <alice@example.com> 1253744424 -0700 746 author Alice <alice@example.com> 1253744424 -0700
748 committer Alice <alice@example.com> 1253744424 -0700 747 committer Alice <alice@example.com> 1253744424 -0700
749 data 13 748 data 13
750 Personalized 749 Personalized
751 from :3 750 from :3
752 M 100644 :4 a 751 M 100644 :4 a
753 M 100644 :5 b 752 M 100644 :5 b
754 753
754 blob
755 mark :7
756 data 5
757 Mooh
758
759 commit refs/heads/feature
760 mark :8
761 author Bob <bob@example.com> 1390311986 -0000
762 committer Bob <bob@example.com> 1390311986 -0000
763 data 6
764 Add C
765 from :3
766 M 100644 :7 c
767
755 reset refs/heads/master 768 reset refs/heads/master
756 from :3 769 from :3
757 """ 770 """
758 def Options(self, *args, **kwargs): 771 def Options(self, *args, **kwargs):
759 return self.OptionsObject(*args, **kwargs) 772 return self.OptionsObject(*args, **kwargs)
760 773
761 @staticmethod 774 @staticmethod
762 def CreateGitRepo(git_import, path): 775 def CreateGitRepo(git_import, path):
763 """Do it for real.""" 776 """Do it for real."""
764 try: 777 try:
(...skipping 13 matching lines...) Expand all
778 Popen(['git', 'push', 'origin', 'origin/origin:origin/master', '-q'], 791 Popen(['git', 'push', 'origin', 'origin/origin:origin/master', '-q'],
779 stdout=PIPE, stderr=STDOUT, cwd=path).communicate() 792 stdout=PIPE, stderr=STDOUT, cwd=path).communicate()
780 Popen(['git', 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE, 793 Popen(['git', 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE,
781 stderr=STDOUT, cwd=path).communicate() 794 stderr=STDOUT, cwd=path).communicate()
782 Popen(['git', 'config', 'user.email', 'someuser@chromium.org'], stdout=PIPE, 795 Popen(['git', 'config', 'user.email', 'someuser@chromium.org'], stdout=PIPE,
783 stderr=STDOUT, cwd=path).communicate() 796 stderr=STDOUT, cwd=path).communicate()
784 Popen(['git', 'config', 'user.name', 'Some User'], stdout=PIPE, 797 Popen(['git', 'config', 'user.name', 'Some User'], stdout=PIPE,
785 stderr=STDOUT, cwd=path).communicate() 798 stderr=STDOUT, cwd=path).communicate()
786 return True 799 return True
787 800
801 def _GetAskForDataCallback(self, expected_prompt, return_value):
802 def AskForData(prompt, options):
803 self.assertEquals(prompt, expected_prompt)
804 return return_value
805 return AskForData
806
788 def setUp(self): 807 def setUp(self):
789 TestCaseUtils.setUp(self) 808 TestCaseUtils.setUp(self)
790 unittest.TestCase.setUp(self) 809 unittest.TestCase.setUp(self)
791 self.url = 'git://foo' 810 self.url = 'git://foo'
792 self.root_dir = tempfile.mkdtemp() 811 self.root_dir = tempfile.mkdtemp()
793 self.relpath = '.' 812 self.relpath = '.'
794 self.base_path = join(self.root_dir, self.relpath) 813 self.base_path = join(self.root_dir, self.relpath)
795 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) 814 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path)
796 StdoutCheck.setUp(self) 815 StdoutCheck.setUp(self)
797 self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists 816 self._original_GitBinaryExists = gclient_scm.GitWrapper.BinaryExists
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] 979 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
961 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 980 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
962 relpath=self.relpath) 981 relpath=self.relpath)
963 file_list = [] 982 file_list = []
964 scm.update(options, (), file_list) 983 scm.update(options, (), file_list)
965 self.assertEquals(file_list, expected_file_list) 984 self.assertEquals(file_list, expected_file_list)
966 self.assertEquals(scm.revinfo(options, (), None), 985 self.assertEquals(scm.revinfo(options, (), None),
967 'a7142dc9f0009350b96a11f372b6ea658592aa95') 986 'a7142dc9f0009350b96a11f372b6ea658592aa95')
968 sys.stdout.close() 987 sys.stdout.close()
969 988
989 def testUpdateMerge(self):
990 if not self.enabled:
991 return
992 options = self.Options()
993 options.merge = True
994 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
995 relpath=self.relpath)
996 scm._Run(['checkout', '-q', 'feature'], options)
997 rev = scm.revinfo(options, (), None)
998 file_list = []
999 scm.update(options, (), file_list)
1000 self.assertEquals(file_list, [join(self.base_path, x)
1001 for x in ['a', 'b', 'c']])
1002 # The actual commit that is created is unstable, so we verify its tree and
1003 # parents instead.
1004 self.assertEquals(scm._Capture(['rev-parse', 'HEAD:']),
1005 'd2e35c10ac24d6c621e14a1fcadceb533155627d')
1006 self.assertEquals(scm._Capture(['rev-parse', 'HEAD^1']), rev)
1007 self.assertEquals(scm._Capture(['rev-parse', 'HEAD^2']),
1008 scm._Capture(['rev-parse', 'origin/master']))
1009 sys.stdout.close()
1010
1011 def testUpdateRebase(self):
1012 if not self.enabled:
1013 return
1014 options = self.Options()
1015 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1016 relpath=self.relpath)
1017 scm._Run(['checkout', '-q', 'feature'], options)
1018 file_list = []
1019 # Fake a 'y' key press.
1020 scm._AskForData = self._GetAskForDataCallback(
1021 'Cannot fast-forward merge, attempt to rebase? '
1022 '(y)es / (q)uit / (s)kip : ', 'y')
1023 scm.update(options, (), file_list)
1024 self.assertEquals(file_list, [join(self.base_path, x)
1025 for x in ['a', 'b', 'c']])
1026 # The actual commit that is created is unstable, so we verify its tree and
1027 # parent instead.
1028 self.assertEquals(scm._Capture(['rev-parse', 'HEAD:']),
1029 'd2e35c10ac24d6c621e14a1fcadceb533155627d')
1030 self.assertEquals(scm._Capture(['rev-parse', 'HEAD^']),
1031 scm._Capture(['rev-parse', 'origin/master']))
1032 sys.stdout.close()
1033
970 def testUpdateReset(self): 1034 def testUpdateReset(self):
971 if not self.enabled: 1035 if not self.enabled:
972 return 1036 return
973 options = self.Options() 1037 options = self.Options()
974 options.reset = True 1038 options.reset = True
975 1039
976 dir_path = join(self.base_path, 'c') 1040 dir_path = join(self.base_path, 'c')
977 os.mkdir(dir_path) 1041 os.mkdir(dir_path)
978 open(join(dir_path, 'nested'), 'w').writelines('new\n') 1042 open(join(dir_path, 'nested'), 'w').writelines('new\n')
979 1043
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 1096
1033 def testUpdateConflict(self): 1097 def testUpdateConflict(self):
1034 if not self.enabled: 1098 if not self.enabled:
1035 return 1099 return
1036 options = self.Options() 1100 options = self.Options()
1037 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1101 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1038 relpath=self.relpath) 1102 relpath=self.relpath)
1039 file_path = join(self.base_path, 'b') 1103 file_path = join(self.base_path, 'b')
1040 open(file_path, 'w').writelines('conflict\n') 1104 open(file_path, 'w').writelines('conflict\n')
1041 scm._Run(['commit', '-am', 'test'], options) 1105 scm._Run(['commit', '-am', 'test'], options)
1042 __builtin__.raw_input = lambda x: 'y' 1106 scm._AskForData = self._GetAskForDataCallback(
1107 'Cannot fast-forward merge, attempt to rebase? '
1108 '(y)es / (q)uit / (s)kip : ', 'y')
1043 exception = ('Conflict while rebasing this branch.\n' 1109 exception = ('Conflict while rebasing this branch.\n'
1044 'Fix the conflict and run gclient again.\n' 1110 'Fix the conflict and run gclient again.\n'
1045 'See \'man git-rebase\' for details.\n') 1111 'See \'man git-rebase\' for details.\n')
1046 self.assertRaisesError(exception, scm.update, options, (), []) 1112 self.assertRaisesError(exception, scm.update, options, (), [])
1047 exception = ('\n____ . at refs/remotes/origin/master\n' 1113 exception = ('\n____ . at refs/remotes/origin/master\n'
1048 '\tYou have unstaged changes.\n' 1114 '\tYou have unstaged changes.\n'
1049 '\tPlease commit, stash, or reset.\n') 1115 '\tPlease commit, stash, or reset.\n')
1050 self.assertRaisesError(exception, scm.update, options, (), []) 1116 self.assertRaisesError(exception, scm.update, options, (), [])
1051 sys.stdout.close() 1117 sys.stdout.close()
1052 1118
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 1271
1206 if __name__ == '__main__': 1272 if __name__ == '__main__':
1207 if '-v' in sys.argv: 1273 if '-v' in sys.argv:
1208 logging.basicConfig( 1274 logging.basicConfig(
1209 level=logging.DEBUG, 1275 level=logging.DEBUG,
1210 format='%(asctime).19s %(levelname)s %(filename)s:' 1276 format='%(asctime).19s %(levelname)s %(filename)s:'
1211 '%(lineno)s %(message)s') 1277 '%(lineno)s %(message)s')
1212 unittest.main() 1278 unittest.main()
1213 1279
1214 # vim: ts=2:sw=2:tw=80:et: 1280 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698