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

Side by Side Diff: tests/gclient_scm_test.py

Issue 183283003: Another attempt: gclient: delete mismatching checkouts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix for unmanaged git-svn, remove commented lines Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « testing_support/fake_repos.py ('k') | tests/gclient_smoketest.py » ('j') | 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.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 def testGITFakeHttpsUrl(self): 128 def testGITFakeHttpsUrl(self):
129 self.url = 'git+https://foo' 129 self.url = 'git+https://foo'
130 130
131 self.mox.ReplayAll() 131 self.mox.ReplayAll()
132 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 132 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
133 relpath=self.relpath) 133 relpath=self.relpath)
134 self.assertEqual(scm.url, 'https://foo') 134 self.assertEqual(scm.url, 'https://foo')
135 135
136 def testRunCommandException(self): 136 def testRunCommandException(self):
137 options = self.Options(verbose=False) 137 options = self.Options(verbose=False)
138 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
139 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 138 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
140 139
141 self.mox.ReplayAll() 140 self.mox.ReplayAll()
142 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 141 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
143 relpath=self.relpath) 142 relpath=self.relpath)
144 exception = "Unsupported argument(s): %s" % ','.join(self.args) 143 exception = "Unsupported argument(s): %s" % ','.join(self.args)
145 self.assertRaisesError(exception, scm.RunCommand, 144 self.assertRaisesError(exception, scm.RunCommand,
146 'update', options, self.args) 145 'update', options, self.args)
147 146
148 def testRunCommandUnknown(self): 147 def testRunCommandUnknown(self):
149 # TODO(maruel): if ever used. 148 # TODO(maruel): if ever used.
150 pass 149 pass
151 150
152 def testRevertMissing(self): 151 def testRevertMissing(self):
153 options = self.Options(verbose=True) 152 options = self.Options(verbose=True)
154 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) 153 gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
155 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 154 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
156 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 155 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
157 ).AndReturn('1.5.1') 156 ).AndReturn('1.5.1')
158 # It'll to a checkout instead. 157 # It'll to a checkout instead.
159 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
160 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 158 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
161 # Checkout. 159 # Checkout.
162 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 160 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
163 parent = gclient_scm.os.path.dirname(self.base_path) 161 parent = gclient_scm.os.path.dirname(self.base_path)
164 gclient_scm.os.path.exists(parent).AndReturn(False) 162 gclient_scm.os.path.exists(parent).AndReturn(False)
165 gclient_scm.os.makedirs(parent) 163 gclient_scm.os.makedirs(parent)
166 gclient_scm.os.path.exists(parent).AndReturn(True) 164 gclient_scm.os.path.exists(parent).AndReturn(True)
167 files_list = self.mox.CreateMockAnything() 165 files_list = self.mox.CreateMockAnything()
168 gclient_scm.scm.SVN.RunAndGetFileList( 166 gclient_scm.scm.SVN.RunAndGetFileList(
169 options.verbose, 167 options.verbose,
(...skipping 11 matching lines...) Expand all
181 self.checkstdout( 179 self.checkstdout(
182 ('\n_____ %s is missing, synching instead\n' % self.relpath)) 180 ('\n_____ %s is missing, synching instead\n' % self.relpath))
183 181
184 def testRevertNoDotSvn(self): 182 def testRevertNoDotSvn(self):
185 options = self.Options(verbose=True, force=True) 183 options = self.Options(verbose=True, force=True)
186 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 184 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
187 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) 185 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
188 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) 186 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
189 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) 187 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
190 # Checkout. 188 # Checkout.
191 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
192 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 189 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
193 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 190 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
194 parent = gclient_scm.os.path.dirname(self.base_path) 191 parent = gclient_scm.os.path.dirname(self.base_path)
195 gclient_scm.os.path.exists(parent).AndReturn(False) 192 gclient_scm.os.path.exists(parent).AndReturn(False)
196 gclient_scm.os.makedirs(parent) 193 gclient_scm.os.makedirs(parent)
197 gclient_scm.os.path.exists(parent).AndReturn(True) 194 gclient_scm.os.path.exists(parent).AndReturn(True)
198 files_list = self.mox.CreateMockAnything() 195 files_list = self.mox.CreateMockAnything()
199 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 196 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
200 ).AndReturn('1.6') 197 ).AndReturn('1.6')
201 gclient_scm.scm.SVN.RunAndGetFileList( 198 gclient_scm.scm.SVN.RunAndGetFileList(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 304
308 # TODO(maruel): TEST REVISIONS!!! 305 # TODO(maruel): TEST REVISIONS!!!
309 # TODO(maruel): TEST RELOCATE!!! 306 # TODO(maruel): TEST RELOCATE!!!
310 def testUpdateCheckout(self): 307 def testUpdateCheckout(self):
311 options = self.Options(verbose=True) 308 options = self.Options(verbose=True)
312 file_info = gclient_scm.gclient_utils.PrintableObject() 309 file_info = gclient_scm.gclient_utils.PrintableObject()
313 file_info.root = 'blah' 310 file_info.root = 'blah'
314 file_info.url = self.url 311 file_info.url = self.url
315 file_info.uuid = 'ABC' 312 file_info.uuid = 'ABC'
316 file_info.revision = 42 313 file_info.revision = 42
317 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
318 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 314 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
319 # Checkout. 315 # Checkout.
320 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 316 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
321 parent = gclient_scm.os.path.dirname(self.base_path) 317 parent = gclient_scm.os.path.dirname(self.base_path)
322 gclient_scm.os.path.exists(parent).AndReturn(False) 318 gclient_scm.os.path.exists(parent).AndReturn(False)
323 gclient_scm.os.makedirs(parent) 319 gclient_scm.os.makedirs(parent)
324 gclient_scm.os.path.exists(parent).AndReturn(True) 320 gclient_scm.os.path.exists(parent).AndReturn(True)
325 files_list = self.mox.CreateMockAnything() 321 files_list = self.mox.CreateMockAnything()
326 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 322 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
327 ).AndReturn('1.5.1') 323 ).AndReturn('1.5.1')
(...skipping 12 matching lines...) Expand all
340 def testUpdateUpdate(self): 336 def testUpdateUpdate(self):
341 options = self.Options(verbose=True) 337 options = self.Options(verbose=True)
342 options.force = True 338 options.force = True
343 options.nohooks = False 339 options.nohooks = False
344 file_info = { 340 file_info = {
345 'Repository Root': 'blah', 341 'Repository Root': 'blah',
346 'URL': self.url, 342 'URL': self.url,
347 'UUID': 'ABC', 343 'UUID': 'ABC',
348 'Revision': 42, 344 'Revision': 42,
349 } 345 }
350 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
351 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 346 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
347 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
348 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
352 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 349 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
353 350
354 # Checkout or update. 351 # Checkout or update.
355 dotted_path = join(self.base_path, '.') 352 dotted_path = join(self.base_path, '.')
356 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 353 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
357 354
358 # Verify no locked files. 355 # Verify no locked files.
359 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 356 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
360 357
361 # Cheat a bit here. 358 # Cheat a bit here.
(...skipping 24 matching lines...) Expand all
386 383
387 def testUpdateReset(self): 384 def testUpdateReset(self):
388 options = self.Options(verbose=True) 385 options = self.Options(verbose=True)
389 options.reset = True 386 options.reset = True
390 file_info = { 387 file_info = {
391 'Repository Root': 'blah', 388 'Repository Root': 'blah',
392 'URL': self.url, 389 'URL': self.url,
393 'UUID': 'ABC', 390 'UUID': 'ABC',
394 'Revision': 42, 391 'Revision': 42,
395 } 392 }
396 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
397 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 393 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
394 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
395 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
398 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 396 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
399 397
400 # Checkout or update. 398 # Checkout or update.
401 dotted_path = join(self.base_path, '.') 399 dotted_path = join(self.base_path, '.')
402 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 400 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
403 401
404 # Create an untracked file and directory. 402 # Create an untracked file and directory.
405 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 403 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
406 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 404 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
407 405
(...skipping 14 matching lines...) Expand all
422 options = self.Options(verbose=True) 420 options = self.Options(verbose=True)
423 options.reset = True 421 options.reset = True
424 options.delete_unversioned_trees = True 422 options.delete_unversioned_trees = True
425 423
426 file_info = { 424 file_info = {
427 'Repository Root': 'blah', 425 'Repository Root': 'blah',
428 'URL': self.url, 426 'URL': self.url,
429 'UUID': 'ABC', 427 'UUID': 'ABC',
430 'Revision': 42, 428 'Revision': 42,
431 } 429 }
432 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
433 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 430 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
431 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
432 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
434 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 433 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
435 434
436 # Checkout or update. 435 # Checkout or update.
437 dotted_path = join(self.base_path, '.') 436 dotted_path = join(self.base_path, '.')
438 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 437 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
439 438
440 # Create an untracked file and directory. 439 # Create an untracked file and directory.
441 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 440 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
442 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 441 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
443 442
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 487 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
489 always=True, 488 always=True,
490 cwd=self.root_dir) 489 cwd=self.root_dir)
491 gclient_scm.scm.SVN.RunAndGetFileList( 490 gclient_scm.scm.SVN.RunAndGetFileList(
492 options.verbose, 491 options.verbose,
493 ['update', 'DEPS', '--ignore-externals'], 492 ['update', 'DEPS', '--ignore-externals'],
494 cwd=self.base_path, 493 cwd=self.base_path,
495 file_list=files_list) 494 file_list=files_list)
496 495
497 # Now we fall back on scm.update(). 496 # Now we fall back on scm.update().
498 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
499 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 497 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
498 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
499 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
500 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 500 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
501 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 501 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
502 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 502 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
503 ).AndReturn(file_info) 503 ).AndReturn(file_info)
504 504
505 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 505 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
506 ).AndReturn({'Revision': 100}) 506 ).AndReturn({'Revision': 100})
507 507
508 self.mox.ReplayAll() 508 self.mox.ReplayAll()
509 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 509 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 558 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
559 always=True, 559 always=True,
560 cwd=self.root_dir) 560 cwd=self.root_dir)
561 gclient_scm.scm.SVN.RunAndGetFileList( 561 gclient_scm.scm.SVN.RunAndGetFileList(
562 options.verbose, 562 options.verbose,
563 ['update', 'DEPS', '--ignore-externals'], 563 ['update', 'DEPS', '--ignore-externals'],
564 cwd=self.base_path, 564 cwd=self.base_path,
565 file_list=files_list) 565 file_list=files_list)
566 566
567 # Now we fall back on scm.update(). 567 # Now we fall back on scm.update().
568 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
569 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 568 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
569 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
570 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
570 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 571 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
571 gclient_scm.scm.SVN._CaptureInfo( 572 gclient_scm.scm.SVN._CaptureInfo(
572 [], join(self.base_path, ".")).AndReturn(file_info) 573 [], join(self.base_path, ".")).AndReturn(file_info)
573 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 574 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
574 ).AndReturn(file_info) 575 ).AndReturn(file_info)
575 576
576 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 577 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
577 ).AndReturn({'Revision': 100}) 578 ).AndReturn({'Revision': 100})
578 579
579 self.mox.ReplayAll() 580 self.mox.ReplayAll()
(...skipping 14 matching lines...) Expand all
594 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 595 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
595 ).AndReturn('1.5.1') 596 ).AndReturn('1.5.1')
596 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) 597 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True)
597 598
598 # Verify no locked files. 599 # Verify no locked files.
599 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') 600 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.')
600 ).AndReturn([]) 601 ).AndReturn([])
601 602
602 # Now we fall back on scm.update(). 603 # Now we fall back on scm.update().
603 files_list = self.mox.CreateMockAnything() 604 files_list = self.mox.CreateMockAnything()
604 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
605 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 605 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
606 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
607 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
606 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 608 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
607 gclient_scm.scm.SVN._CaptureInfo( 609 gclient_scm.scm.SVN._CaptureInfo(
608 [], join(self.base_path, '.')).AndReturn(file_info) 610 [], join(self.base_path, '.')).AndReturn(file_info)
609 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 611 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
610 ).AndReturn(file_info) 612 ).AndReturn(file_info)
611 613
612 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 614 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
613 ).AndReturn({'Revision': 100}) 615 ).AndReturn({'Revision': 100})
614 616
615 self.mox.ReplayAll() 617 self.mox.ReplayAll()
616 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 618 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
617 relpath=self.relpath) 619 relpath=self.relpath)
618 scm.updatesingle(options, ['DEPS'], files_list) 620 scm.updatesingle(options, ['DEPS'], files_list)
619 self.checkstdout('\n_____ %s at 42\n' % self.relpath) 621 self.checkstdout('\n_____ %s at 42\n' % self.relpath)
620 622
621 def testUpdateGit(self): 623 def testUpdateGit(self):
622 options = self.Options(verbose=True) 624 options = self.Options(verbose=True)
623 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 625 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
624 gclient_scm.os.path.exists(file_path).AndReturn(True) 626 gclient_scm.os.path.exists(file_path).AndReturn(False)
627 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
628 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
629 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
630 error = gclient_scm.subprocess2.CalledProcessError(
631 1, 'cmd', '/cwd', 'stdout', 'stderr')
632 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
633
634 self.mox.ReplayAll()
635 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
636 relpath=self.relpath)
637 error = ('Can\'t update/checkout %s if an unversioned directory is '
638 'present. Delete the directory and try again.' % self.base_path)
639 self.assertRaisesError(error, scm.update, options, None, [])
640
641 def testUpdateGitForce(self):
642 options = self.Options(verbose=True, force=True)
643 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
644 gclient_scm.os.path.exists(file_path).AndReturn(False)
645 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
646 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
647 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
648 error = gclient_scm.subprocess2.CalledProcessError(
649 1, 'cmd', '/cwd', 'stdout', 'stderr')
650 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
651 gclient_scm.gclient_utils.rmtree(self.base_path)
652 gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
653 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
654 ).AndReturn('1.5.1')
655 gclient_scm.scm.SVN.RunAndGetFileList(
656 options.verbose,
657 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
658 cwd=self.root_dir,
659 file_list=[])
660
661 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
662 ).AndReturn({'Revision': 100})
625 663
626 self.mox.ReplayAll() 664 self.mox.ReplayAll()
627 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 665 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
628 relpath=self.relpath) 666 relpath=self.relpath)
629 file_list = [] 667 file_list = []
630 scm.update(options, self.args, file_list) 668 scm.update(options, None, file_list)
669 self.checkstdout('Removing troublesome path %s\n' % self.base_path)
670
671 def testUpdateGitSvn(self):
672 options = self.Options(verbose=True)
673 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
674 gclient_scm.os.path.exists(file_path).AndReturn(False)
675 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
676 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
677 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True)
678 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
679 gclient_scm.scm.GIT.Capture(['config', '--local', '--get',
680 'svn-remote.svn.url'],
681 cwd=self.base_path).AndReturn(self.url)
682
683 self.mox.ReplayAll()
684 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
685 relpath=self.relpath)
686 file_list = []
687 scm.update(options, [], file_list)
631 self.checkstdout( 688 self.checkstdout(
632 ('________ found .git directory; skipping %s\n' % self.relpath)) 689 ('\n_____ %s looks like a git-svn checkout. Skipping.\n' % self.relpath)
690 )
633 691
634 def testUpdateHg(self): 692 def testUpdateHg(self):
635 options = self.Options(verbose=True) 693 options = self.Options(verbose=True)
636 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
637 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) 694 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True)
638 695
639 self.mox.ReplayAll() 696 self.mox.ReplayAll()
640 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 697 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
641 relpath=self.relpath) 698 relpath=self.relpath)
642 file_list = [] 699 file_list = []
643 scm.update(options, self.args, file_list) 700 scm.update(options, self.args, file_list)
644 self.checkstdout( 701 self.checkstdout(
645 ('________ found .hg directory; skipping %s\n' % self.relpath)) 702 ('________ found .hg directory; skipping %s\n' % self.relpath))
646 703
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 self.assertEquals(git_svn_scm.GetUsableRev('3', options), 1248 self.assertEquals(git_svn_scm.GetUsableRev('3', options),
1192 self.fake_hash_2) 1249 self.fake_hash_2)
1193 # Given a git sha1 with a git-svn checkout, it should be used as is. 1250 # Given a git sha1 with a git-svn checkout, it should be used as is.
1194 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), 1251 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options),
1195 self.fake_hash_1) 1252 self.fake_hash_1)
1196 # We currently check for seemingly valid SVN revisions by assuming 6 digit 1253 # We currently check for seemingly valid SVN revisions by assuming 6 digit
1197 # numbers, so assure that numeric revs >= 1000000 don't work. 1254 # numbers, so assure that numeric revs >= 1000000 don't work.
1198 self.assertRaises(gclient_scm.gclient_utils.Error, 1255 self.assertRaises(gclient_scm.gclient_utils.Error,
1199 git_svn_scm.GetUsableRev, too_big, options) 1256 git_svn_scm.GetUsableRev, too_big, options)
1200 1257
1258 def testUpdateNoDotGit(self):
1259 options = self.Options()
1260
1261 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1262 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1263 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1264 ).AndReturn(False)
1265 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1266 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1267 ).AndReturn(False)
1268
1269 self.mox.ReplayAll()
1270 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1271 relpath=self.relpath)
1272 error = ('\n____ %s at refs/remotes/origin/master\n\tPath is not a git '
1273 'repo. No .git dir.\n\tTo resolve:\n\t\trm -rf %s\n\tAnd run '
1274 'gclient sync again\n\tOr run with --force\n' % (self.relpath,
1275 self.relpath))
1276 self.assertRaisesError(error, scm.update, options, None, [])
1277
1278 def testUpdateNoDotGitForce(self):
1279 options = self.Options(force=True)
1280
1281 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1282 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1283 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1284 ).AndReturn(False)
1285 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1286 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1287 ).AndReturn(False)
1288 gclient_scm.gclient_utils.rmtree(self.base_path)
1289 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
1290 # pylint: disable=E1120
1291 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
1292 options)
1293 # pylint: disable=E1120
1294 self.mox.StubOutWithMock(gclient_scm.GitWrapper, 'UpdateSubmoduleConfig',
1295 True)
1296 gclient_scm.GitWrapper.UpdateSubmoduleConfig()
1297 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
1298 gclient_scm.subprocess2.check_output(['git', 'ls-files'],
1299 cwd=self.base_path,
1300 stderr=gclient_scm.subprocess2.VOID,
1301 ).AndReturn('')
1302 gclient_scm.subprocess2.check_output(
1303 ['git', 'rev-parse', '--verify', 'HEAD'],
1304 cwd=self.base_path,
1305 stderr=gclient_scm.subprocess2.VOID,
1306 ).AndReturn('')
1307
1308 self.mox.ReplayAll()
1309 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1310 relpath=self.relpath)
1311 scm.update(options, None, [])
1312 self.checkstdout('_____ Conflicting directory found in %s. Removing.\n\n'
1313 % self.base_path)
1314
1201 1315
1202 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): 1316 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
1203 def testUpdateUpdate(self): 1317 def testUpdateUpdate(self):
1204 if not self.enabled: 1318 if not self.enabled:
1205 return 1319 return
1206 options = self.Options() 1320 options = self.Options()
1207 expected_file_list = [] 1321 expected_file_list = []
1208 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1322 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1209 relpath=self.relpath) 1323 relpath=self.relpath)
1210 file_list = [] 1324 file_list = []
1211 options.revision = 'unmanaged' 1325 options.revision = 'unmanaged'
1212 scm.update(options, (), file_list) 1326 scm.update(options, (), file_list)
1213 self.assertEquals(file_list, expected_file_list) 1327 self.assertEquals(file_list, expected_file_list)
1214 self.assertEquals(scm.revinfo(options, (), None), 1328 self.assertEquals(scm.revinfo(options, (), None),
1215 '069c602044c5388d2d15c3f875b057c852003458') 1329 '069c602044c5388d2d15c3f875b057c852003458')
1216 self.checkstdout('________ unmanaged solution; skipping .\n') 1330 self.checkstdout('________ unmanaged solution; skipping .\n')
1217 1331
1218 1332
1219 if __name__ == '__main__': 1333 if __name__ == '__main__':
1220 if '-v' in sys.argv: 1334 if '-v' in sys.argv:
1221 logging.basicConfig( 1335 logging.basicConfig(
1222 level=logging.DEBUG, 1336 level=logging.DEBUG,
1223 format='%(asctime).19s %(levelname)s %(filename)s:' 1337 format='%(asctime).19s %(levelname)s %(filename)s:'
1224 '%(lineno)s %(message)s') 1338 '%(lineno)s %(message)s')
1225 unittest.main() 1339 unittest.main()
1226 1340
1227 # vim: ts=2:sw=2:tw=80:et: 1341 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « testing_support/fake_repos.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698