OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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 # Import before super_mox to keep valid references. | 8 # Import before super_mox to keep valid references. |
9 from os import rename | 9 from os import rename |
10 from shutil import rmtree | 10 from shutil import rmtree |
11 import StringIO | 11 import StringIO |
12 from subprocess import Popen, PIPE, STDOUT | 12 from subprocess import Popen, PIPE, STDOUT |
13 import tempfile | 13 import tempfile |
14 import unittest | 14 import unittest |
15 import __builtin__ | 15 import __builtin__ |
16 | 16 |
17 # Fixes include path. | 17 # Fixes include path. |
18 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase | 18 from super_mox import mox, StdoutCheck, TestCaseUtils, SuperMoxTestBase |
19 | 19 |
20 import gclient_scm | 20 import gclient_scm |
21 | 21 |
| 22 # Shortcut since this function is used often |
| 23 join = gclient_scm.os.path.join |
| 24 |
22 | 25 |
23 class GCBaseTestCase(object): | 26 class GCBaseTestCase(object): |
24 def assertRaisesError(self, msg, fn, *args, **kwargs): | 27 def assertRaisesError(self, msg, fn, *args, **kwargs): |
25 """Like unittest's assertRaises() but checks for Gclient.Error.""" | 28 """Like unittest's assertRaises() but checks for Gclient.Error.""" |
26 try: | 29 try: |
27 fn(*args, **kwargs) | 30 fn(*args, **kwargs) |
28 except gclient_scm.gclient_utils.Error, e: | 31 except gclient_scm.gclient_utils.Error, e: |
29 self.assertEquals(e.args[0], msg) | 32 self.assertEquals(e.args[0], msg) |
30 else: | 33 else: |
31 self.fail('%s not raised' % msg) | 34 self.fail('%s not raised' % msg) |
(...skipping 10 matching lines...) Expand all Loading... |
42 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') | 45 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'FileWrite') |
43 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'Popen') | 46 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'Popen') |
44 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') | 47 self.mox.StubOutWithMock(gclient_scm.gclient_utils, 'RemoveDirectory') |
45 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo | 48 self._CaptureSVNInfo = gclient_scm.scm.SVN.CaptureInfo |
46 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') | 49 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'Capture') |
47 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') | 50 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureInfo') |
48 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') | 51 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'CaptureStatus') |
49 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') | 52 self.mox.StubOutWithMock(gclient_scm.scm.SVN, 'RunAndGetFileList') |
50 self._scm_wrapper = gclient_scm.CreateSCM | 53 self._scm_wrapper = gclient_scm.CreateSCM |
51 gclient_scm.scm.SVN.current_version = None | 54 gclient_scm.scm.SVN.current_version = None |
| 55 # Absolute path of the fake checkout directory. |
| 56 self.base_path = join(self.root_dir, self.relpath) |
52 | 57 |
53 def tearDown(self): | 58 def tearDown(self): |
54 SuperMoxTestBase.tearDown(self) | 59 SuperMoxTestBase.tearDown(self) |
55 | 60 |
56 | 61 |
57 class SVNWrapperTestCase(BaseTestCase): | 62 class SVNWrapperTestCase(BaseTestCase): |
58 class OptionsObject(object): | 63 class OptionsObject(object): |
59 def __init__(self, verbose=False, revision=None): | 64 def __init__(self, verbose=False, revision=None): |
60 self.verbose = verbose | 65 self.verbose = verbose |
61 self.revision = revision | 66 self.revision = revision |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 def testGITFullUrlForRelativeUrl(self): | 104 def testGITFullUrlForRelativeUrl(self): |
100 self.url = 'git://a/b/c/d' | 105 self.url = 'git://a/b/c/d' |
101 | 106 |
102 self.mox.ReplayAll() | 107 self.mox.ReplayAll() |
103 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 108 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
104 relpath=self.relpath) | 109 relpath=self.relpath) |
105 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap') | 110 self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'git://a/b/c/crap') |
106 | 111 |
107 def testRunCommandException(self): | 112 def testRunCommandException(self): |
108 options = self.Options(verbose=False) | 113 options = self.Options(verbose=False) |
109 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 114 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
110 gclient_scm.os.path.exists(file_path).AndReturn(False) | 115 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
111 | 116 |
112 self.mox.ReplayAll() | 117 self.mox.ReplayAll() |
113 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 118 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
114 relpath=self.relpath) | 119 relpath=self.relpath) |
115 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 120 exception = "Unsupported argument(s): %s" % ','.join(self.args) |
116 self.assertRaisesError(exception, scm.RunCommand, | 121 self.assertRaisesError(exception, scm.RunCommand, |
117 'update', options, self.args) | 122 'update', options, self.args) |
118 | 123 |
119 def testRunCommandUnknown(self): | 124 def testRunCommandUnknown(self): |
120 # TODO(maruel): if ever used. | 125 # TODO(maruel): if ever used. |
121 pass | 126 pass |
122 | 127 |
123 def testRevertMissing(self): | 128 def testRevertMissing(self): |
124 options = self.Options(verbose=True) | 129 options = self.Options(verbose=True) |
125 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 130 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) |
126 gclient_scm.os.path.isdir(base_path).AndReturn(False) | |
127 gclient_scm.scm.SVN.Capture(['--version'] | 131 gclient_scm.scm.SVN.Capture(['--version'] |
128 ).AndReturn('svn, version 1.5.1 (r32289)') | 132 ).AndReturn('svn, version 1.5.1 (r32289)') |
129 # It'll to a checkout instead. | 133 # It'll to a checkout instead. |
130 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 134 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
131 ).AndReturn(False) | 135 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
132 # Checkout. | 136 # Checkout. |
133 gclient_scm.os.path.exists(base_path).AndReturn(False) | 137 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
134 files_list = self.mox.CreateMockAnything() | 138 files_list = self.mox.CreateMockAnything() |
135 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 139 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
136 ['checkout', self.url, base_path, | 140 ['checkout', self.url, self.base_path, |
137 '--force'], | 141 '--force'], |
138 cwd=self.root_dir, | 142 cwd=self.root_dir, |
139 file_list=files_list) | 143 file_list=files_list) |
140 | 144 |
141 self.mox.ReplayAll() | 145 self.mox.ReplayAll() |
142 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 146 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
143 relpath=self.relpath) | 147 relpath=self.relpath) |
144 scm.revert(options, self.args, files_list) | 148 scm.revert(options, self.args, files_list) |
145 self.checkstdout( | 149 self.checkstdout( |
146 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 150 ('\n_____ %s is missing, synching instead\n' % self.relpath)) |
147 | 151 |
148 def testRevertNone(self): | 152 def testRevertNone(self): |
149 options = self.Options(verbose=True) | 153 options = self.Options(verbose=True) |
150 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 154 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
151 gclient_scm.os.path.isdir(base_path).AndReturn(True) | 155 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn([]) |
152 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn([]) | |
153 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 156 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
154 ['update', '--revision', 'BASE'], | 157 ['update', '--revision', 'BASE'], |
155 cwd=base_path, | 158 cwd=self.base_path, |
156 file_list=mox.IgnoreArg()) | 159 file_list=mox.IgnoreArg()) |
157 | 160 |
158 self.mox.ReplayAll() | 161 self.mox.ReplayAll() |
159 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 162 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
160 relpath=self.relpath) | 163 relpath=self.relpath) |
161 file_list = [] | 164 file_list = [] |
162 scm.revert(options, self.args, file_list) | 165 scm.revert(options, self.args, file_list) |
163 | 166 |
164 def testRevert2Files(self): | 167 def testRevert2Files(self): |
165 options = self.Options(verbose=True) | 168 options = self.Options(verbose=True) |
166 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 169 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
167 gclient_scm.os.path.isdir(base_path).AndReturn(True) | |
168 items = [ | 170 items = [ |
169 ('M ', 'a'), | 171 ('M ', 'a'), |
170 ('A ', 'b'), | 172 ('A ', 'b'), |
171 ] | 173 ] |
172 file_path1 = gclient_scm.os.path.join(base_path, 'a') | 174 file_path1 = join(self.base_path, 'a') |
173 file_path2 = gclient_scm.os.path.join(base_path, 'b') | 175 file_path2 = join(self.base_path, 'b') |
174 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) | 176 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) |
175 gclient_scm.os.path.exists(file_path1).AndReturn(True) | 177 gclient_scm.os.path.exists(file_path1).AndReturn(True) |
176 gclient_scm.os.path.isfile(file_path1).AndReturn(True) | 178 gclient_scm.os.path.isfile(file_path1).AndReturn(True) |
177 gclient_scm.os.remove(file_path1) | 179 gclient_scm.os.remove(file_path1) |
178 gclient_scm.os.path.exists(file_path2).AndReturn(True) | 180 gclient_scm.os.path.exists(file_path2).AndReturn(True) |
179 gclient_scm.os.path.isfile(file_path2).AndReturn(True) | 181 gclient_scm.os.path.isfile(file_path2).AndReturn(True) |
180 gclient_scm.os.remove(file_path2) | 182 gclient_scm.os.remove(file_path2) |
181 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 183 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
182 ['update', '--revision', 'BASE'], | 184 ['update', '--revision', 'BASE'], |
183 cwd=base_path, | 185 cwd=self.base_path, |
184 file_list=mox.IgnoreArg()) | 186 file_list=mox.IgnoreArg()) |
185 | 187 |
186 self.mox.ReplayAll() | 188 self.mox.ReplayAll() |
187 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 189 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
188 relpath=self.relpath) | 190 relpath=self.relpath) |
189 file_list = [] | 191 file_list = [] |
190 scm.revert(options, self.args, file_list) | 192 scm.revert(options, self.args, file_list) |
191 self.checkstdout( | 193 self.checkstdout( |
192 ('%s\n%s\n' % (gclient_scm.os.path.join(base_path, 'a'), | 194 ('%s\n%s\n' % (join(self.base_path, 'a'), |
193 gclient_scm.os.path.join(base_path, 'b')))) | 195 join(self.base_path, 'b')))) |
194 | 196 |
195 def testRevertDirectory(self): | 197 def testRevertDirectory(self): |
196 options = self.Options(verbose=True) | 198 options = self.Options(verbose=True) |
197 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 199 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
198 gclient_scm.os.path.isdir(base_path).AndReturn(True) | |
199 items = [ | 200 items = [ |
200 ('~ ', 'a'), | 201 ('~ ', 'a'), |
201 ] | 202 ] |
202 gclient_scm.scm.SVN.CaptureStatus(base_path).AndReturn(items) | 203 gclient_scm.scm.SVN.CaptureStatus(self.base_path).AndReturn(items) |
203 file_path = gclient_scm.os.path.join(base_path, 'a') | 204 file_path = join(self.base_path, 'a') |
204 gclient_scm.os.path.exists(file_path).AndReturn(True) | 205 gclient_scm.os.path.exists(file_path).AndReturn(True) |
205 gclient_scm.os.path.isfile(file_path).AndReturn(False) | 206 gclient_scm.os.path.isfile(file_path).AndReturn(False) |
206 gclient_scm.os.path.islink(file_path).AndReturn(False) | 207 gclient_scm.os.path.islink(file_path).AndReturn(False) |
207 gclient_scm.os.path.isdir(file_path).AndReturn(True) | 208 gclient_scm.os.path.isdir(file_path).AndReturn(True) |
208 gclient_scm.gclient_utils.RemoveDirectory(file_path) | 209 gclient_scm.gclient_utils.RemoveDirectory(file_path) |
209 file_list1 = [] | 210 file_list1 = [] |
210 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 211 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
211 ['update', '--revision', 'BASE'], | 212 ['update', '--revision', 'BASE'], |
212 cwd=base_path, | 213 cwd=self.base_path, |
213 file_list=mox.IgnoreArg()) | 214 file_list=mox.IgnoreArg()) |
214 | 215 |
215 self.mox.ReplayAll() | 216 self.mox.ReplayAll() |
216 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 217 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
217 relpath=self.relpath) | 218 relpath=self.relpath) |
218 file_list2 = [] | 219 file_list2 = [] |
219 scm.revert(options, self.args, file_list2) | 220 scm.revert(options, self.args, file_list2) |
220 self.checkstdout(('%s\n' % file_path)) | 221 self.checkstdout(('%s\n' % file_path)) |
221 | 222 |
222 def testStatus(self): | 223 def testStatus(self): |
223 options = self.Options(verbose=True) | 224 options = self.Options(verbose=True) |
224 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 225 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) |
225 gclient_scm.os.path.isdir(base_path).AndReturn(True) | |
226 gclient_scm.scm.SVN.RunAndGetFileList( | 226 gclient_scm.scm.SVN.RunAndGetFileList( |
227 options.verbose, ['status'] + self.args, | 227 options.verbose, ['status'] + self.args, |
228 cwd=base_path, file_list=[]).AndReturn(None) | 228 cwd=self.base_path, file_list=[]).AndReturn(None) |
229 | 229 |
230 self.mox.ReplayAll() | 230 self.mox.ReplayAll() |
231 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 231 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
232 relpath=self.relpath) | 232 relpath=self.relpath) |
233 file_list = [] | 233 file_list = [] |
234 self.assertEqual(scm.status(options, self.args, file_list), None) | 234 self.assertEqual(scm.status(options, self.args, file_list), None) |
235 | 235 |
236 # TODO(maruel): TEST REVISIONS!!! | 236 # TODO(maruel): TEST REVISIONS!!! |
237 # TODO(maruel): TEST RELOCATE!!! | 237 # TODO(maruel): TEST RELOCATE!!! |
238 def testUpdateCheckout(self): | 238 def testUpdateCheckout(self): |
239 options = self.Options(verbose=True) | 239 options = self.Options(verbose=True) |
240 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | |
241 file_info = gclient_scm.gclient_utils.PrintableObject() | 240 file_info = gclient_scm.gclient_utils.PrintableObject() |
242 file_info.root = 'blah' | 241 file_info.root = 'blah' |
243 file_info.url = self.url | 242 file_info.url = self.url |
244 file_info.uuid = 'ABC' | 243 file_info.uuid = 'ABC' |
245 file_info.revision = 42 | 244 file_info.revision = 42 |
246 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 245 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
247 ).AndReturn(False) | 246 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
248 # Checkout. | 247 # Checkout. |
249 gclient_scm.os.path.exists(base_path).AndReturn(False) | 248 gclient_scm.os.path.exists(self.base_path).AndReturn(False) |
250 files_list = self.mox.CreateMockAnything() | 249 files_list = self.mox.CreateMockAnything() |
251 gclient_scm.scm.SVN.Capture(['--version'] | 250 gclient_scm.scm.SVN.Capture(['--version'] |
252 ).AndReturn('svn, version 1.5.1 (r32289)') | 251 ).AndReturn('svn, version 1.5.1 (r32289)') |
253 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, | 252 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, |
254 ['checkout', self.url, base_path, | 253 ['checkout', self.url, self.base_path, |
255 '--force'], | 254 '--force'], |
256 cwd=self.root_dir, | 255 cwd=self.root_dir, |
257 file_list=files_list) | 256 file_list=files_list) |
258 self.mox.ReplayAll() | 257 self.mox.ReplayAll() |
259 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 258 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
260 relpath=self.relpath) | 259 relpath=self.relpath) |
261 scm.update(options, (), files_list) | 260 scm.update(options, (), files_list) |
262 | 261 |
263 def testUpdateUpdate(self): | 262 def testUpdateUpdate(self): |
264 options = self.Options(verbose=True) | 263 options = self.Options(verbose=True) |
265 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | |
266 options.force = True | 264 options.force = True |
267 options.nohooks = False | 265 options.nohooks = False |
268 file_info = { | 266 file_info = { |
269 'Repository Root': 'blah', | 267 'Repository Root': 'blah', |
270 'URL': self.url, | 268 'URL': self.url, |
271 'UUID': 'ABC', | 269 'UUID': 'ABC', |
272 'Revision': 42, | 270 'Revision': 42, |
273 } | 271 } |
274 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 272 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
275 ).AndReturn(False) | 273 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
276 | 274 |
277 # Verify no locked files. | 275 # Verify no locked files. |
278 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') | 276 dotted_path = join(self.base_path, '.') |
279 ).AndReturn([]) | 277 gclient_scm.scm.SVN.CaptureStatus(dotted_path).AndReturn([]) |
280 | 278 |
281 # Checkout or update. | 279 # Checkout or update. |
282 gclient_scm.os.path.exists(base_path).AndReturn(True) | 280 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
283 gclient_scm.scm.SVN.CaptureInfo( | 281 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) |
284 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) | |
285 # Cheat a bit here. | 282 # Cheat a bit here. |
286 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 283 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
287 additional_args = [] | 284 additional_args = [] |
288 if options.manually_grab_svn_rev: | 285 if options.manually_grab_svn_rev: |
289 additional_args = ['--revision', str(file_info['Revision'])] | 286 additional_args = ['--revision', str(file_info['Revision'])] |
290 gclient_scm.scm.SVN.Capture(['--version'] | 287 gclient_scm.scm.SVN.Capture(['--version'] |
291 ).AndReturn('svn, version 1.5.1 (r32289)') | 288 ).AndReturn('svn, version 1.5.1 (r32289)') |
292 additional_args.append('--force') | 289 additional_args.append('--force') |
293 files_list = [] | 290 files_list = [] |
294 gclient_scm.scm.SVN.RunAndGetFileList( | 291 gclient_scm.scm.SVN.RunAndGetFileList( |
295 options.verbose, | 292 options.verbose, |
296 ['update', base_path] + additional_args, | 293 ['update', self.base_path] + additional_args, |
297 cwd=self.root_dir, file_list=files_list) | 294 cwd=self.root_dir, file_list=files_list) |
298 | 295 |
299 self.mox.ReplayAll() | 296 self.mox.ReplayAll() |
300 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 297 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
301 relpath=self.relpath) | 298 relpath=self.relpath) |
302 scm.update(options, (), files_list) | 299 scm.update(options, (), files_list) |
303 | 300 |
304 def testUpdateSingleCheckout(self): | 301 def testUpdateSingleCheckout(self): |
305 options = self.Options(verbose=True) | 302 options = self.Options(verbose=True) |
306 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | |
307 file_info = { | 303 file_info = { |
308 'URL': self.url, | 304 'URL': self.url, |
309 'Revision': 42, | 305 'Revision': 42, |
310 } | 306 } |
311 | 307 |
312 # Checks to make sure that we support svn co --depth. | 308 # Checks to make sure that we support svn co --depth. |
313 gclient_scm.scm.SVN.current_version = None | 309 gclient_scm.scm.SVN.current_version = None |
314 gclient_scm.scm.SVN.Capture(['--version'] | 310 gclient_scm.scm.SVN.Capture(['--version'] |
315 ).AndReturn('svn, version 1.5.1 (r32289)') | 311 ).AndReturn('svn, version 1.5.1 (r32289)') |
316 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.svn') | 312 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) |
317 ).AndReturn(False) | 313 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(False) |
318 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, 'DEPS') | |
319 ).AndReturn(False) | |
320 | 314 |
321 # Verify no locked files. | 315 # Verify no locked files. |
322 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') | 316 dotted_path = join(self.base_path, '.') |
323 ).AndReturn([]) | 317 gclient_scm.scm.SVN.CaptureStatus(dotted_path).AndReturn([]) |
324 | 318 |
325 # When checking out a single file, we issue an svn checkout and svn update. | 319 # When checking out a single file, we issue an svn checkout and svn update. |
326 files_list = self.mox.CreateMockAnything() | 320 files_list = self.mox.CreateMockAnything() |
327 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 321 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
328 ['svn', 'checkout', '--depth', 'empty', self.url, base_path], | 322 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
329 always=True, cwd=self.root_dir) | 323 always=True, cwd=self.root_dir) |
330 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], | 324 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], |
331 cwd=base_path, file_list=files_list) | 325 cwd=self.base_path, file_list=files_list) |
332 | 326 |
333 # Now we fall back on scm.update(). | 327 # Now we fall back on scm.update(). |
334 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 328 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
335 ).AndReturn(False) | 329 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
336 gclient_scm.os.path.exists(base_path).AndReturn(True) | 330 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
337 gclient_scm.scm.SVN.CaptureInfo( | 331 gclient_scm.scm.SVN.CaptureInfo(dotted_path).AndReturn(file_info) |
338 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) | |
339 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 332 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
340 | 333 |
341 self.mox.ReplayAll() | 334 self.mox.ReplayAll() |
342 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 335 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
343 relpath=self.relpath) | 336 relpath=self.relpath) |
344 scm.updatesingle(options, ['DEPS'], files_list) | 337 scm.updatesingle(options, ['DEPS'], files_list) |
345 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 338 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
346 | 339 |
347 def testUpdateSingleCheckoutSVN14(self): | 340 def testUpdateSingleCheckoutSVN14(self): |
348 options = self.Options(verbose=True) | 341 options = self.Options(verbose=True) |
349 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | |
350 file_info = { | 342 file_info = { |
351 'URL': self.url, | 343 'URL': self.url, |
352 'Revision': 42, | 344 'Revision': 42, |
353 } | 345 } |
354 | 346 |
355 # Checks to make sure that we support svn co --depth. | 347 # Checks to make sure that we support svn co --depth. |
356 gclient_scm.scm.SVN.current_version = None | 348 gclient_scm.scm.SVN.current_version = None |
357 gclient_scm.scm.SVN.Capture(['--version'] | 349 gclient_scm.scm.SVN.Capture(['--version'] |
358 ).AndReturn('svn, version 1.4.4 (r25188)') | 350 ).AndReturn('svn, version 1.4.4 (r25188)') |
359 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path) | 351 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
360 ).AndReturn(True) | |
361 | 352 |
362 # When checking out a single file with svn 1.4, we use svn export | 353 # When checking out a single file with svn 1.4, we use svn export |
363 files_list = self.mox.CreateMockAnything() | 354 files_list = self.mox.CreateMockAnything() |
364 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 355 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
365 ['svn', 'export', gclient_scm.os.path.join(self.url, 'DEPS'), | 356 ['svn', 'export', join(self.url, 'DEPS'), join(self.base_path, 'DEPS')], |
366 gclient_scm.os.path.join(base_path, 'DEPS')], | |
367 always=True, cwd=self.root_dir) | 357 always=True, cwd=self.root_dir) |
368 | 358 |
369 self.mox.ReplayAll() | 359 self.mox.ReplayAll() |
370 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 360 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
371 relpath=self.relpath) | 361 relpath=self.relpath) |
372 scm.updatesingle(options, ['DEPS'], files_list) | 362 scm.updatesingle(options, ['DEPS'], files_list) |
373 | 363 |
374 def testUpdateSingleCheckoutSVNUpgrade(self): | 364 def testUpdateSingleCheckoutSVNUpgrade(self): |
375 options = self.Options(verbose=True) | 365 options = self.Options(verbose=True) |
376 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | |
377 file_info = { | 366 file_info = { |
378 'URL': self.url, | 367 'URL': self.url, |
379 'Revision': 42, | 368 'Revision': 42, |
380 } | 369 } |
381 | 370 |
382 # Checks to make sure that we support svn co --depth. | 371 # Checks to make sure that we support svn co --depth. |
383 gclient_scm.scm.SVN.current_version = None | 372 gclient_scm.scm.SVN.current_version = None |
384 gclient_scm.scm.SVN.Capture(['--version'] | 373 gclient_scm.scm.SVN.Capture(['--version'] |
385 ).AndReturn('svn, version 1.5.1 (r32289)') | 374 ).AndReturn('svn, version 1.5.1 (r32289)') |
386 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.svn') | 375 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(False) |
387 ).AndReturn(False) | |
388 # If DEPS already exists, assume we're upgrading from svn1.4, so delete | 376 # If DEPS already exists, assume we're upgrading from svn1.4, so delete |
389 # the old DEPS file. | 377 # the old DEPS file. |
390 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, 'DEPS') | 378 gclient_scm.os.path.exists(join(self.base_path, 'DEPS')).AndReturn(True) |
391 ).AndReturn(True) | 379 gclient_scm.os.remove(join(self.base_path, 'DEPS')) |
392 gclient_scm.os.remove(gclient_scm.os.path.join(base_path, 'DEPS')) | |
393 | 380 |
394 # Verify no locked files. | 381 # Verify no locked files. |
395 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') | 382 gclient_scm.scm.SVN.CaptureStatus(join(self.base_path, '.')).AndReturn([]) |
396 ).AndReturn([]) | |
397 | 383 |
398 # When checking out a single file, we issue an svn checkout and svn update. | 384 # When checking out a single file, we issue an svn checkout and svn update. |
399 files_list = self.mox.CreateMockAnything() | 385 files_list = self.mox.CreateMockAnything() |
400 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( | 386 gclient_scm.gclient_utils.CheckCallAndFilterAndHeader( |
401 ['svn', 'checkout', '--depth', 'empty', self.url, base_path], | 387 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], |
402 always=True, cwd=self.root_dir) | 388 always=True, cwd=self.root_dir) |
403 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], | 389 gclient_scm.scm.SVN.RunAndGetFileList(options.verbose, ['update', 'DEPS'], |
404 cwd=base_path, file_list=files_list) | 390 cwd=self.base_path, file_list=files_list) |
405 | 391 |
406 # Now we fall back on scm.update(). | 392 # Now we fall back on scm.update(). |
407 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 393 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
408 ).AndReturn(False) | 394 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
409 gclient_scm.os.path.exists(base_path).AndReturn(True) | 395 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
410 gclient_scm.scm.SVN.CaptureInfo( | 396 gclient_scm.scm.SVN.CaptureInfo( |
411 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) | 397 join(self.base_path, ".")).AndReturn(file_info) |
412 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 398 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
413 | 399 |
414 self.mox.ReplayAll() | 400 self.mox.ReplayAll() |
415 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 401 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
416 relpath=self.relpath) | 402 relpath=self.relpath) |
417 scm.updatesingle(options, ['DEPS'], files_list) | 403 scm.updatesingle(options, ['DEPS'], files_list) |
418 self.checkstdout( | 404 self.checkstdout( |
419 ('\n_____ %s at 42\n' % self.relpath)) | 405 ('\n_____ %s at 42\n' % self.relpath)) |
420 | 406 |
421 def testUpdateSingleUpdate(self): | 407 def testUpdateSingleUpdate(self): |
422 options = self.Options(verbose=True) | 408 options = self.Options(verbose=True) |
423 base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | |
424 file_info = { | 409 file_info = { |
425 'URL': self.url, | 410 'URL': self.url, |
426 'Revision': 42, | 411 'Revision': 42, |
427 } | 412 } |
428 # Checks to make sure that we support svn co --depth. | 413 # Checks to make sure that we support svn co --depth. |
429 gclient_scm.scm.SVN.current_version = None | 414 gclient_scm.scm.SVN.current_version = None |
430 gclient_scm.scm.SVN.Capture(['--version'] | 415 gclient_scm.scm.SVN.Capture(['--version'] |
431 ).AndReturn('svn, version 1.5.1 (r32289)') | 416 ).AndReturn('svn, version 1.5.1 (r32289)') |
432 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.svn') | 417 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) |
433 ).AndReturn(True) | |
434 | 418 |
435 # Verify no locked files. | 419 # Verify no locked files. |
436 gclient_scm.scm.SVN.CaptureStatus(gclient_scm.os.path.join(base_path, '.') | 420 gclient_scm.scm.SVN.CaptureStatus(join(self.base_path, '.')).AndReturn([]) |
437 ).AndReturn([]) | |
438 | 421 |
439 # Now we fall back on scm.update(). | 422 # Now we fall back on scm.update(). |
440 files_list = self.mox.CreateMockAnything() | 423 files_list = self.mox.CreateMockAnything() |
441 gclient_scm.os.path.exists(gclient_scm.os.path.join(base_path, '.git') | 424 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
442 ).AndReturn(False) | 425 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) |
443 gclient_scm.os.path.exists(base_path).AndReturn(True) | 426 gclient_scm.os.path.exists(self.base_path).AndReturn(True) |
444 gclient_scm.scm.SVN.CaptureInfo( | 427 gclient_scm.scm.SVN.CaptureInfo( |
445 gclient_scm.os.path.join(base_path, ".")).AndReturn(file_info) | 428 join(self.base_path, '.')).AndReturn(file_info) |
446 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) | 429 gclient_scm.scm.SVN.CaptureInfo(file_info['URL']).AndReturn(file_info) |
447 | 430 |
448 self.mox.ReplayAll() | 431 self.mox.ReplayAll() |
449 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 432 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
450 relpath=self.relpath) | 433 relpath=self.relpath) |
451 scm.updatesingle(options, ['DEPS'], files_list) | 434 scm.updatesingle(options, ['DEPS'], files_list) |
452 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 435 self.checkstdout('\n_____ %s at 42\n' % self.relpath) |
453 | 436 |
454 def testUpdateGit(self): | 437 def testUpdateGit(self): |
455 options = self.Options(verbose=True) | 438 options = self.Options(verbose=True) |
456 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 439 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') |
457 gclient_scm.os.path.exists(file_path).AndReturn(True) | 440 gclient_scm.os.path.exists(file_path).AndReturn(True) |
458 | 441 |
459 self.mox.ReplayAll() | 442 self.mox.ReplayAll() |
460 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 443 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
461 relpath=self.relpath) | 444 relpath=self.relpath) |
462 file_list = [] | 445 file_list = [] |
463 scm.update(options, self.args, file_list) | 446 scm.update(options, self.args, file_list) |
464 self.checkstdout( | 447 self.checkstdout( |
465 ('________ found .git directory; skipping %s\n' % self.relpath)) | 448 ('________ found .git directory; skipping %s\n' % self.relpath)) |
466 | 449 |
| 450 def testUpdateHg(self): |
| 451 options = self.Options(verbose=True) |
| 452 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) |
| 453 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) |
| 454 |
| 455 self.mox.ReplayAll() |
| 456 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, |
| 457 relpath=self.relpath) |
| 458 file_list = [] |
| 459 scm.update(options, self.args, file_list) |
| 460 self.checkstdout( |
| 461 ('________ found .hg directory; skipping %s\n' % self.relpath)) |
| 462 |
467 | 463 |
468 class GitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, | 464 class GitWrapperTestCase(GCBaseTestCase, StdoutCheck, TestCaseUtils, |
469 unittest.TestCase): | 465 unittest.TestCase): |
470 """This class doesn't use pymox.""" | 466 """This class doesn't use pymox.""" |
471 class OptionsObject(object): | 467 class OptionsObject(object): |
472 def __init__(self, verbose=False, revision=None): | 468 def __init__(self, verbose=False, revision=None): |
473 self.verbose = verbose | 469 self.verbose = verbose |
474 self.revision = revision | 470 self.revision = revision |
475 self.manually_grab_svn_rev = True | 471 self.manually_grab_svn_rev = True |
476 self.deps_os = None | 472 self.deps_os = None |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 Popen(['git', 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE, | 543 Popen(['git', 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE, |
548 stderr=STDOUT, cwd=path).communicate() | 544 stderr=STDOUT, cwd=path).communicate() |
549 return True | 545 return True |
550 | 546 |
551 def setUp(self): | 547 def setUp(self): |
552 TestCaseUtils.setUp(self) | 548 TestCaseUtils.setUp(self) |
553 unittest.TestCase.setUp(self) | 549 unittest.TestCase.setUp(self) |
554 self.url = 'git://foo' | 550 self.url = 'git://foo' |
555 self.root_dir = tempfile.mkdtemp() | 551 self.root_dir = tempfile.mkdtemp() |
556 self.relpath = '.' | 552 self.relpath = '.' |
557 self.base_path = gclient_scm.os.path.join(self.root_dir, self.relpath) | 553 self.base_path = join(self.root_dir, self.relpath) |
558 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) | 554 self.enabled = self.CreateGitRepo(self.sample_git_import, self.base_path) |
559 StdoutCheck.setUp(self) | 555 StdoutCheck.setUp(self) |
560 | 556 |
561 def tearDown(self): | 557 def tearDown(self): |
562 StdoutCheck.tearDown(self) | 558 StdoutCheck.tearDown(self) |
563 TestCaseUtils.tearDown(self) | 559 TestCaseUtils.tearDown(self) |
564 unittest.TestCase.tearDown(self) | 560 unittest.TestCase.tearDown(self) |
565 rmtree(self.root_dir) | 561 rmtree(self.root_dir) |
566 | 562 |
567 def testDir(self): | 563 def testDir(self): |
568 members = [ | 564 members = [ |
569 'FullUrlForRelativeUrl', 'RunCommand', | 565 'FullUrlForRelativeUrl', 'RunCommand', |
570 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', | 566 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', |
571 'revinfo', 'runhooks', 'status', 'update', 'url', | 567 'revinfo', 'runhooks', 'status', 'update', 'url', |
572 ] | 568 ] |
573 | 569 |
574 # If you add a member, be sure to add the relevant test! | 570 # If you add a member, be sure to add the relevant test! |
575 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) | 571 self.compareMembers(gclient_scm.CreateSCM(url=self.url), members) |
576 | 572 |
577 def testRevertMissing(self): | 573 def testRevertMissing(self): |
578 if not self.enabled: | 574 if not self.enabled: |
579 return | 575 return |
580 options = self.Options() | 576 options = self.Options() |
581 file_path = gclient_scm.os.path.join(self.base_path, 'a') | 577 file_path = join(self.base_path, 'a') |
582 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 578 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
583 relpath=self.relpath) | 579 relpath=self.relpath) |
584 file_list = [] | 580 file_list = [] |
585 scm.update(options, None, file_list) | 581 scm.update(options, None, file_list) |
586 gclient_scm.os.remove(file_path) | 582 gclient_scm.os.remove(file_path) |
587 file_list = [] | 583 file_list = [] |
588 scm.revert(options, self.args, file_list) | 584 scm.revert(options, self.args, file_list) |
589 self.assertEquals(file_list, [file_path]) | 585 self.assertEquals(file_list, [file_path]) |
590 file_list = [] | 586 file_list = [] |
591 scm.diff(options, self.args, file_list) | 587 scm.diff(options, self.args, file_list) |
592 self.assertEquals(file_list, []) | 588 self.assertEquals(file_list, []) |
593 self.checkstdout( | 589 self.checkstdout( |
594 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 590 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
595 'Fast-forward\n a | 1 +\n b | 1 +\n' | 591 'Fast-forward\n a | 1 +\n b | 1 +\n' |
596 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 592 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
597 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 593 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
598 'HEAD is now at a7142dc Personalized\n') % | 594 'HEAD is now at a7142dc Personalized\n') % |
599 gclient_scm.os.path.join(self.root_dir, '.')) | 595 join(self.root_dir, '.')) |
600 | 596 |
601 def testRevertNone(self): | 597 def testRevertNone(self): |
602 if not self.enabled: | 598 if not self.enabled: |
603 return | 599 return |
604 options = self.Options() | 600 options = self.Options() |
605 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 601 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
606 relpath=self.relpath) | 602 relpath=self.relpath) |
607 file_list = [] | 603 file_list = [] |
608 scm.update(options, None, file_list) | 604 scm.update(options, None, file_list) |
609 file_list = [] | 605 file_list = [] |
610 scm.revert(options, self.args, file_list) | 606 scm.revert(options, self.args, file_list) |
611 self.assertEquals(file_list, []) | 607 self.assertEquals(file_list, []) |
612 self.assertEquals(scm.revinfo(options, self.args, None), | 608 self.assertEquals(scm.revinfo(options, self.args, None), |
613 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 609 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
614 self.checkstdout( | 610 self.checkstdout( |
615 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 611 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
616 'Fast-forward\n a | 1 +\n b | 1 +\n' | 612 'Fast-forward\n a | 1 +\n b | 1 +\n' |
617 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 613 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
618 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 614 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
619 'HEAD is now at a7142dc Personalized\n') % | 615 'HEAD is now at a7142dc Personalized\n') % |
620 gclient_scm.os.path.join(self.root_dir, '.')) | 616 join(self.root_dir, '.')) |
621 | 617 |
622 def testRevertModified(self): | 618 def testRevertModified(self): |
623 if not self.enabled: | 619 if not self.enabled: |
624 return | 620 return |
625 options = self.Options() | 621 options = self.Options() |
626 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 622 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
627 relpath=self.relpath) | 623 relpath=self.relpath) |
628 file_list = [] | 624 file_list = [] |
629 scm.update(options, None, file_list) | 625 scm.update(options, None, file_list) |
630 file_path = gclient_scm.os.path.join(self.base_path, 'a') | 626 file_path = join(self.base_path, 'a') |
631 open(file_path, 'a').writelines('touched\n') | 627 open(file_path, 'a').writelines('touched\n') |
632 file_list = [] | 628 file_list = [] |
633 scm.revert(options, self.args, file_list) | 629 scm.revert(options, self.args, file_list) |
634 self.assertEquals(file_list, [file_path]) | 630 self.assertEquals(file_list, [file_path]) |
635 file_list = [] | 631 file_list = [] |
636 scm.diff(options, self.args, file_list) | 632 scm.diff(options, self.args, file_list) |
637 self.assertEquals(file_list, []) | 633 self.assertEquals(file_list, []) |
638 self.assertEquals(scm.revinfo(options, self.args, None), | 634 self.assertEquals(scm.revinfo(options, self.args, None), |
639 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 635 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
640 self.checkstdout( | 636 self.checkstdout( |
641 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 637 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
642 'Fast-forward\n a | 1 +\n b | 1 +\n' | 638 'Fast-forward\n a | 1 +\n b | 1 +\n' |
643 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 639 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
644 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 640 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
645 'HEAD is now at a7142dc Personalized\n') % | 641 'HEAD is now at a7142dc Personalized\n') % |
646 gclient_scm.os.path.join(self.root_dir, '.')) | 642 join(self.root_dir, '.')) |
647 | 643 |
648 def testRevertNew(self): | 644 def testRevertNew(self): |
649 if not self.enabled: | 645 if not self.enabled: |
650 return | 646 return |
651 options = self.Options() | 647 options = self.Options() |
652 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 648 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
653 relpath=self.relpath) | 649 relpath=self.relpath) |
654 file_list = [] | 650 file_list = [] |
655 scm.update(options, None, file_list) | 651 scm.update(options, None, file_list) |
656 file_path = gclient_scm.os.path.join(self.base_path, 'c') | 652 file_path = join(self.base_path, 'c') |
657 f = open(file_path, 'w') | 653 f = open(file_path, 'w') |
658 f.writelines('new\n') | 654 f.writelines('new\n') |
659 f.close() | 655 f.close() |
660 Popen(['git', 'add', 'c'], stdout=PIPE, | 656 Popen(['git', 'add', 'c'], stdout=PIPE, |
661 stderr=STDOUT, cwd=self.base_path).communicate() | 657 stderr=STDOUT, cwd=self.base_path).communicate() |
662 file_list = [] | 658 file_list = [] |
663 scm.revert(options, self.args, file_list) | 659 scm.revert(options, self.args, file_list) |
664 self.assertEquals(file_list, [file_path]) | 660 self.assertEquals(file_list, [file_path]) |
665 file_list = [] | 661 file_list = [] |
666 scm.diff(options, self.args, file_list) | 662 scm.diff(options, self.args, file_list) |
667 self.assertEquals(file_list, []) | 663 self.assertEquals(file_list, []) |
668 self.assertEquals(scm.revinfo(options, self.args, None), | 664 self.assertEquals(scm.revinfo(options, self.args, None), |
669 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 665 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
670 self.checkstdout( | 666 self.checkstdout( |
671 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' | 667 ('\n_____ . at refs/heads/master\nUpdating 069c602..a7142dc\n' |
672 'Fast-forward\n a | 1 +\n b | 1 +\n' | 668 'Fast-forward\n a | 1 +\n b | 1 +\n' |
673 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' | 669 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n\n' |
674 '________ running \'git reset --hard origin/master\' in \'%s\'\n' | 670 '________ running \'git reset --hard origin/master\' in \'%s\'\n' |
675 'HEAD is now at a7142dc Personalized\n') % | 671 'HEAD is now at a7142dc Personalized\n') % |
676 gclient_scm.os.path.join(self.root_dir, '.')) | 672 join(self.root_dir, '.')) |
677 | 673 |
678 def testStatusNew(self): | 674 def testStatusNew(self): |
679 if not self.enabled: | 675 if not self.enabled: |
680 return | 676 return |
681 options = self.Options() | 677 options = self.Options() |
682 file_path = gclient_scm.os.path.join(self.base_path, 'a') | 678 file_path = join(self.base_path, 'a') |
683 open(file_path, 'a').writelines('touched\n') | 679 open(file_path, 'a').writelines('touched\n') |
684 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 680 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
685 relpath=self.relpath) | 681 relpath=self.relpath) |
686 file_list = [] | 682 file_list = [] |
687 scm.status(options, self.args, file_list) | 683 scm.status(options, self.args, file_list) |
688 self.assertEquals(file_list, [file_path]) | 684 self.assertEquals(file_list, [file_path]) |
689 self.checkstdout( | 685 self.checkstdout( |
690 ('\n________ running \'git diff --name-status ' | 686 ('\n________ running \'git diff --name-status ' |
691 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\n') % | 687 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\n') % |
692 gclient_scm.os.path.join(self.root_dir, '.')) | 688 join(self.root_dir, '.')) |
693 | 689 |
694 def testStatus2New(self): | 690 def testStatus2New(self): |
695 if not self.enabled: | 691 if not self.enabled: |
696 return | 692 return |
697 options = self.Options() | 693 options = self.Options() |
698 expected_file_list = [] | 694 expected_file_list = [] |
699 for f in ['a', 'b']: | 695 for f in ['a', 'b']: |
700 file_path = gclient_scm.os.path.join(self.base_path, f) | 696 file_path = join(self.base_path, f) |
701 open(file_path, 'a').writelines('touched\n') | 697 open(file_path, 'a').writelines('touched\n') |
702 expected_file_list.extend([file_path]) | 698 expected_file_list.extend([file_path]) |
703 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 699 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
704 relpath=self.relpath) | 700 relpath=self.relpath) |
705 file_list = [] | 701 file_list = [] |
706 scm.status(options, self.args, file_list) | 702 scm.status(options, self.args, file_list) |
707 expected_file_list = [gclient_scm.os.path.join(self.base_path, x) | 703 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] |
708 for x in ['a', 'b']] | |
709 self.assertEquals(sorted(file_list), expected_file_list) | 704 self.assertEquals(sorted(file_list), expected_file_list) |
710 self.checkstdout( | 705 self.checkstdout( |
711 ('\n________ running \'git diff --name-status ' | 706 ('\n________ running \'git diff --name-status ' |
712 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\nM\tb\n') % | 707 '069c602044c5388d2d15c3f875b057c852003458\' in \'%s\'\nM\ta\nM\tb\n') % |
713 gclient_scm.os.path.join(self.root_dir, '.')) | 708 join(self.root_dir, '.')) |
714 | 709 |
715 def testUpdateCheckout(self): | 710 def testUpdateCheckout(self): |
716 if not self.enabled: | 711 if not self.enabled: |
717 return | 712 return |
718 options = self.Options(verbose=True) | 713 options = self.Options(verbose=True) |
719 root_dir = tempfile.mkdtemp() | 714 root_dir = tempfile.mkdtemp() |
720 relpath = 'foo' | 715 relpath = 'foo' |
721 base_path = gclient_scm.os.path.join(root_dir, relpath) | 716 base_path = join(root_dir, relpath) |
722 url = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 717 url = join(self.base_path, '.git') |
723 try: | 718 try: |
724 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, | 719 scm = gclient_scm.CreateSCM(url=url, root_dir=root_dir, |
725 relpath=relpath) | 720 relpath=relpath) |
726 file_list = [] | 721 file_list = [] |
727 scm.update(options, (), file_list) | 722 scm.update(options, (), file_list) |
728 self.assertEquals(len(file_list), 2) | 723 self.assertEquals(len(file_list), 2) |
729 self.assert_(gclient_scm.os.path.isfile( | 724 self.assert_(gclient_scm.os.path.isfile(join(base_path, 'a'))) |
730 gclient_scm.os.path.join(base_path, 'a'))) | |
731 self.assertEquals(scm.revinfo(options, (), None), | 725 self.assertEquals(scm.revinfo(options, (), None), |
732 '069c602044c5388d2d15c3f875b057c852003458') | 726 '069c602044c5388d2d15c3f875b057c852003458') |
733 finally: | 727 finally: |
734 rmtree(root_dir) | 728 rmtree(root_dir) |
735 join = gclient_scm.os.path.join | |
736 self.checkstdout( | 729 self.checkstdout( |
737 ('\n_____ foo at refs/heads/master\n\n' | 730 ('\n_____ foo at refs/heads/master\n\n' |
738 '________ running \'git clone -b master --verbose %s %s\' in \'%s\'\n' | 731 '________ running \'git clone -b master --verbose %s %s\' in \'%s\'\n' |
739 'Initialized empty Git repository in %s\n') % | 732 'Initialized empty Git repository in %s\n') % |
740 (join(self.root_dir, '.', '.git'), join(root_dir, 'foo'), root_dir, | 733 (join(self.root_dir, '.', '.git'), join(root_dir, 'foo'), root_dir, |
741 join(root_dir, 'foo', '.git') + '/')) | 734 join(root_dir, 'foo', '.git') + '/')) |
742 | 735 |
743 def testUpdateUpdate(self): | 736 def testUpdateUpdate(self): |
744 if not self.enabled: | 737 if not self.enabled: |
745 return | 738 return |
746 options = self.Options() | 739 options = self.Options() |
747 expected_file_list = [gclient_scm.os.path.join(self.base_path, x) | 740 expected_file_list = [join(self.base_path, x) for x in ['a', 'b']] |
748 for x in ['a', 'b']] | |
749 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 741 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
750 relpath=self.relpath) | 742 relpath=self.relpath) |
751 file_list = [] | 743 file_list = [] |
752 scm.update(options, (), file_list) | 744 scm.update(options, (), file_list) |
753 self.assertEquals(file_list, expected_file_list) | 745 self.assertEquals(file_list, expected_file_list) |
754 self.assertEquals(scm.revinfo(options, (), None), | 746 self.assertEquals(scm.revinfo(options, (), None), |
755 'a7142dc9f0009350b96a11f372b6ea658592aa95') | 747 'a7142dc9f0009350b96a11f372b6ea658592aa95') |
756 self.checkstdout( | 748 self.checkstdout( |
757 '\n_____ . at refs/heads/master\n' | 749 '\n_____ . at refs/heads/master\n' |
758 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' | 750 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' |
759 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') | 751 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') |
760 | 752 |
761 def testUpdateUnstagedConflict(self): | 753 def testUpdateUnstagedConflict(self): |
762 if not self.enabled: | 754 if not self.enabled: |
763 return | 755 return |
764 options = self.Options() | 756 options = self.Options() |
765 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 757 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
766 relpath=self.relpath) | 758 relpath=self.relpath) |
767 file_path = gclient_scm.os.path.join(self.base_path, 'b') | 759 file_path = join(self.base_path, 'b') |
768 f = open(file_path, 'w').writelines('conflict\n') | 760 f = open(file_path, 'w').writelines('conflict\n') |
769 exception = ( | 761 exception = ( |
770 "error: Your local changes to 'b' would be overwritten by merge. " | 762 "error: Your local changes to 'b' would be overwritten by merge. " |
771 "Aborting.\n" | 763 "Aborting.\n" |
772 "Please, commit your changes or stash them before you can merge.\n") | 764 "Please, commit your changes or stash them before you can merge.\n") |
773 self.assertRaisesError(exception, scm.update, options, (), []) | 765 self.assertRaisesError(exception, scm.update, options, (), []) |
774 self.checkstdout('\n_____ . at refs/heads/master\n') | 766 self.checkstdout('\n_____ . at refs/heads/master\n') |
775 | 767 |
776 def testUpdateConflict(self): | 768 def testUpdateConflict(self): |
777 if not self.enabled: | 769 if not self.enabled: |
778 return | 770 return |
779 options = self.Options() | 771 options = self.Options() |
780 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 772 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
781 relpath=self.relpath) | 773 relpath=self.relpath) |
782 file_path = gclient_scm.os.path.join(self.base_path, 'b') | 774 file_path = join(self.base_path, 'b') |
783 f = open(file_path, 'w').writelines('conflict\n') | 775 f = open(file_path, 'w').writelines('conflict\n') |
784 scm._Run(['commit', '-am', 'test'], options) | 776 scm._Run(['commit', '-am', 'test'], options) |
785 __builtin__.raw_input = lambda x: 'y' | 777 __builtin__.raw_input = lambda x: 'y' |
786 exception = ('Conflict while rebasing this branch.\n' | 778 exception = ('Conflict while rebasing this branch.\n' |
787 'Fix the conflict and run gclient again.\n' | 779 'Fix the conflict and run gclient again.\n' |
788 'See \'man git-rebase\' for details.\n') | 780 'See \'man git-rebase\' for details.\n') |
789 self.assertRaisesError(exception, scm.update, options, (), []) | 781 self.assertRaisesError(exception, scm.update, options, (), []) |
790 exception = ('\n____ . at refs/heads/master\n' | 782 exception = ('\n____ . at refs/heads/master\n' |
791 '\tYou have unstaged changes.\n' | 783 '\tYou have unstaged changes.\n' |
792 '\tPlease commit, stash, or reset.\n') | 784 '\tPlease commit, stash, or reset.\n') |
793 self.assertRaisesError(exception, scm.update, options, (), []) | 785 self.assertRaisesError(exception, scm.update, options, (), []) |
794 # The hash always changes. Use a cheap trick. | 786 # The hash always changes. Use a cheap trick. |
795 start = ('\n________ running \'git commit -am test\' in \'%s\'\n' | 787 start = ('\n________ running \'git commit -am test\' in \'%s\'\n' |
796 '[new ') % gclient_scm.os.path.join(self.root_dir, '.') | 788 '[new ') % join(self.root_dir, '.') |
797 end = ('] test\n 1 files changed, 1 insertions(+), ' | 789 end = ('] test\n 1 files changed, 1 insertions(+), ' |
798 '1 deletions(-)\n\n_____ . at refs/heads/master\n' | 790 '1 deletions(-)\n\n_____ . at refs/heads/master\n' |
799 'Attempting rebase onto refs/remotes/origin/master...\n') | 791 'Attempting rebase onto refs/remotes/origin/master...\n') |
800 self.assertTrue(gclient_scm.sys.stdout.getvalue().startswith(start)) | 792 self.assertTrue(gclient_scm.sys.stdout.getvalue().startswith(start)) |
801 self.assertTrue(gclient_scm.sys.stdout.getvalue().endswith(end)) | 793 self.assertTrue(gclient_scm.sys.stdout.getvalue().endswith(end)) |
802 self.assertEquals(len(gclient_scm.sys.stdout.getvalue()), | 794 self.assertEquals(len(gclient_scm.sys.stdout.getvalue()), |
803 len(start) + len(end) + 7) | 795 len(start) + len(end) + 7) |
804 gclient_scm.sys.stdout.close() | 796 gclient_scm.sys.stdout.close() |
805 | 797 |
806 def testUpdateNotGit(self): | 798 def testUpdateNotGit(self): |
807 if not self.enabled: | 799 if not self.enabled: |
808 return | 800 return |
809 options = self.Options() | 801 options = self.Options() |
810 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 802 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
811 relpath=self.relpath) | 803 relpath=self.relpath) |
812 git_path = gclient_scm.os.path.join(self.base_path, '.git') | 804 git_path = join(self.base_path, '.git') |
813 rename(git_path, git_path + 'foo') | 805 rename(git_path, git_path + 'foo') |
814 exception = ('\n____ . at refs/heads/master\n' | 806 exception = ('\n____ . at refs/heads/master\n' |
815 '\tPath is not a git repo. No .git dir.\n' | 807 '\tPath is not a git repo. No .git dir.\n' |
816 '\tTo resolve:\n' | 808 '\tTo resolve:\n' |
817 '\t\trm -rf .\n' | 809 '\t\trm -rf .\n' |
818 '\tAnd run gclient sync again\n') | 810 '\tAnd run gclient sync again\n') |
819 self.assertRaisesError(exception, scm.update, options, (), []) | 811 self.assertRaisesError(exception, scm.update, options, (), []) |
820 | 812 |
821 def testRevinfo(self): | 813 def testRevinfo(self): |
822 if not self.enabled: | 814 if not self.enabled: |
823 return | 815 return |
824 options = self.Options() | 816 options = self.Options() |
825 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 817 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, |
826 relpath=self.relpath) | 818 relpath=self.relpath) |
827 rev_info = scm.revinfo(options, (), None) | 819 rev_info = scm.revinfo(options, (), None) |
828 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') | 820 self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') |
829 | 821 |
830 | 822 |
831 if __name__ == '__main__': | 823 if __name__ == '__main__': |
832 unittest.main() | 824 unittest.main() |
833 | 825 |
834 # vim: ts=2:sw=2:tw=80:et: | 826 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |