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

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: Add GitWrapper tests for conflicting directories 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 | « scm.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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 def testGITFakeHttpsUrl(self): 154 def testGITFakeHttpsUrl(self):
155 self.url = 'git+https://foo' 155 self.url = 'git+https://foo'
156 156
157 self.mox.ReplayAll() 157 self.mox.ReplayAll()
158 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 158 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
159 relpath=self.relpath) 159 relpath=self.relpath)
160 self.assertEqual(scm.url, 'https://foo') 160 self.assertEqual(scm.url, 'https://foo')
161 161
162 def testRunCommandException(self): 162 def testRunCommandException(self):
163 options = self.Options(verbose=False) 163 options = self.Options(verbose=False)
164 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
165 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 164 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
166 165
167 self.mox.ReplayAll() 166 self.mox.ReplayAll()
168 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 167 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
169 relpath=self.relpath) 168 relpath=self.relpath)
170 exception = "Unsupported argument(s): %s" % ','.join(self.args) 169 exception = "Unsupported argument(s): %s" % ','.join(self.args)
171 self.assertRaisesError(exception, scm.RunCommand, 170 self.assertRaisesError(exception, scm.RunCommand,
172 'update', options, self.args) 171 'update', options, self.args)
173 172
174 def testRunCommandUnknown(self): 173 def testRunCommandUnknown(self):
175 # TODO(maruel): if ever used. 174 # TODO(maruel): if ever used.
176 pass 175 pass
177 176
178 def testRevertMissing(self): 177 def testRevertMissing(self):
179 options = self.Options(verbose=True) 178 options = self.Options(verbose=True)
180 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) 179 gclient_scm.os.path.isdir(self.base_path).AndReturn(False)
181 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 180 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
182 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 181 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
183 ).AndReturn('1.5.1') 182 ).AndReturn('1.5.1')
184 # It'll to a checkout instead. 183 # It'll to a checkout instead.
185 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
186 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 184 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
187 # Checkout. 185 # Checkout.
188 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 186 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
189 parent = gclient_scm.os.path.dirname(self.base_path) 187 parent = gclient_scm.os.path.dirname(self.base_path)
190 gclient_scm.os.path.exists(parent).AndReturn(False) 188 gclient_scm.os.path.exists(parent).AndReturn(False)
191 gclient_scm.os.makedirs(parent) 189 gclient_scm.os.makedirs(parent)
192 gclient_scm.os.path.exists(parent).AndReturn(True) 190 gclient_scm.os.path.exists(parent).AndReturn(True)
193 files_list = self.mox.CreateMockAnything() 191 files_list = self.mox.CreateMockAnything()
194 gclient_scm.scm.SVN.RunAndGetFileList( 192 gclient_scm.scm.SVN.RunAndGetFileList(
195 options.verbose, 193 options.verbose,
(...skipping 11 matching lines...) Expand all
207 self.checkstdout( 205 self.checkstdout(
208 ('\n_____ %s is missing, synching instead\n' % self.relpath)) 206 ('\n_____ %s is missing, synching instead\n' % self.relpath))
209 207
210 def testRevertNoDotSvn(self): 208 def testRevertNoDotSvn(self):
211 options = self.Options(verbose=True, force=True) 209 options = self.Options(verbose=True, force=True)
212 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 210 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
213 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) 211 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False)
214 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) 212 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False)
215 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) 213 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False)
216 # Checkout. 214 # Checkout.
217 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
218 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 215 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
219 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 216 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
220 parent = gclient_scm.os.path.dirname(self.base_path) 217 parent = gclient_scm.os.path.dirname(self.base_path)
221 gclient_scm.os.path.exists(parent).AndReturn(False) 218 gclient_scm.os.path.exists(parent).AndReturn(False)
222 gclient_scm.os.makedirs(parent) 219 gclient_scm.os.makedirs(parent)
223 gclient_scm.os.path.exists(parent).AndReturn(True) 220 gclient_scm.os.path.exists(parent).AndReturn(True)
224 files_list = self.mox.CreateMockAnything() 221 files_list = self.mox.CreateMockAnything()
225 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 222 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
226 ).AndReturn('1.6') 223 ).AndReturn('1.6')
227 gclient_scm.scm.SVN.RunAndGetFileList( 224 gclient_scm.scm.SVN.RunAndGetFileList(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 330
334 # TODO(maruel): TEST REVISIONS!!! 331 # TODO(maruel): TEST REVISIONS!!!
335 # TODO(maruel): TEST RELOCATE!!! 332 # TODO(maruel): TEST RELOCATE!!!
336 def testUpdateCheckout(self): 333 def testUpdateCheckout(self):
337 options = self.Options(verbose=True) 334 options = self.Options(verbose=True)
338 file_info = gclient_scm.gclient_utils.PrintableObject() 335 file_info = gclient_scm.gclient_utils.PrintableObject()
339 file_info.root = 'blah' 336 file_info.root = 'blah'
340 file_info.url = self.url 337 file_info.url = self.url
341 file_info.uuid = 'ABC' 338 file_info.uuid = 'ABC'
342 file_info.revision = 42 339 file_info.revision = 42
343 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
344 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 340 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
345 # Checkout. 341 # Checkout.
346 gclient_scm.os.path.exists(self.base_path).AndReturn(False) 342 gclient_scm.os.path.exists(self.base_path).AndReturn(False)
347 parent = gclient_scm.os.path.dirname(self.base_path) 343 parent = gclient_scm.os.path.dirname(self.base_path)
348 gclient_scm.os.path.exists(parent).AndReturn(False) 344 gclient_scm.os.path.exists(parent).AndReturn(False)
349 gclient_scm.os.makedirs(parent) 345 gclient_scm.os.makedirs(parent)
350 gclient_scm.os.path.exists(parent).AndReturn(True) 346 gclient_scm.os.path.exists(parent).AndReturn(True)
351 files_list = self.mox.CreateMockAnything() 347 files_list = self.mox.CreateMockAnything()
352 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 348 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
353 ).AndReturn('1.5.1') 349 ).AndReturn('1.5.1')
(...skipping 12 matching lines...) Expand all
366 def testUpdateUpdate(self): 362 def testUpdateUpdate(self):
367 options = self.Options(verbose=True) 363 options = self.Options(verbose=True)
368 options.force = True 364 options.force = True
369 options.nohooks = False 365 options.nohooks = False
370 file_info = { 366 file_info = {
371 'Repository Root': 'blah', 367 'Repository Root': 'blah',
372 'URL': self.url, 368 'URL': self.url,
373 'UUID': 'ABC', 369 'UUID': 'ABC',
374 'Revision': 42, 370 'Revision': 42,
375 } 371 }
376 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
377 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 372 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
373 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
374 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(False)
378 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 375 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
379 376
380 # Checkout or update. 377 # Checkout or update.
381 dotted_path = join(self.base_path, '.') 378 dotted_path = join(self.base_path, '.')
382 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 379 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
383 380
384 # Verify no locked files. 381 # Verify no locked files.
385 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 382 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
386 383
387 # Cheat a bit here. 384 # Cheat a bit here.
(...skipping 24 matching lines...) Expand all
412 409
413 def testUpdateReset(self): 410 def testUpdateReset(self):
414 options = self.Options(verbose=True) 411 options = self.Options(verbose=True)
415 options.reset = True 412 options.reset = True
416 file_info = { 413 file_info = {
417 'Repository Root': 'blah', 414 'Repository Root': 'blah',
418 'URL': self.url, 415 'URL': self.url,
419 'UUID': 'ABC', 416 'UUID': 'ABC',
420 'Revision': 42, 417 'Revision': 42,
421 } 418 }
422 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
423 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 419 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
420 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
421 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(False)
424 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 422 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
425 423
426 # Checkout or update. 424 # Checkout or update.
427 dotted_path = join(self.base_path, '.') 425 dotted_path = join(self.base_path, '.')
428 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 426 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
429 427
430 # Create an untracked file and directory. 428 # Create an untracked file and directory.
431 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 429 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
432 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 430 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
433 431
(...skipping 14 matching lines...) Expand all
448 options = self.Options(verbose=True) 446 options = self.Options(verbose=True)
449 options.reset = True 447 options.reset = True
450 options.delete_unversioned_trees = True 448 options.delete_unversioned_trees = True
451 449
452 file_info = { 450 file_info = {
453 'Repository Root': 'blah', 451 'Repository Root': 'blah',
454 'URL': self.url, 452 'URL': self.url,
455 'UUID': 'ABC', 453 'UUID': 'ABC',
456 'Revision': 42, 454 'Revision': 42,
457 } 455 }
458 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
459 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 456 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
457 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
458 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(False)
460 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 459 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
461 460
462 # Checkout or update. 461 # Checkout or update.
463 dotted_path = join(self.base_path, '.') 462 dotted_path = join(self.base_path, '.')
464 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 463 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
465 464
466 # Create an untracked file and directory. 465 # Create an untracked file and directory.
467 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path 466 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
468 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) 467 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
469 468
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 513 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
515 always=True, 514 always=True,
516 cwd=self.root_dir) 515 cwd=self.root_dir)
517 gclient_scm.scm.SVN.RunAndGetFileList( 516 gclient_scm.scm.SVN.RunAndGetFileList(
518 options.verbose, 517 options.verbose,
519 ['update', 'DEPS', '--ignore-externals'], 518 ['update', 'DEPS', '--ignore-externals'],
520 cwd=self.base_path, 519 cwd=self.base_path,
521 file_list=files_list) 520 file_list=files_list)
522 521
523 # Now we fall back on scm.update(). 522 # Now we fall back on scm.update().
524 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
525 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 523 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
524 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
525 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(False)
526 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 526 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
527 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 527 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
528 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 528 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
529 ).AndReturn(file_info) 529 ).AndReturn(file_info)
530 530
531 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 531 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
532 ).AndReturn({'Revision': 100}) 532 ).AndReturn({'Revision': 100})
533 533
534 self.mox.ReplayAll() 534 self.mox.ReplayAll()
535 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 535 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], 584 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path],
585 always=True, 585 always=True,
586 cwd=self.root_dir) 586 cwd=self.root_dir)
587 gclient_scm.scm.SVN.RunAndGetFileList( 587 gclient_scm.scm.SVN.RunAndGetFileList(
588 options.verbose, 588 options.verbose,
589 ['update', 'DEPS', '--ignore-externals'], 589 ['update', 'DEPS', '--ignore-externals'],
590 cwd=self.base_path, 590 cwd=self.base_path,
591 file_list=files_list) 591 file_list=files_list)
592 592
593 # Now we fall back on scm.update(). 593 # Now we fall back on scm.update().
594 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
595 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 594 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
595 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
596 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(False)
596 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 597 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
597 gclient_scm.scm.SVN._CaptureInfo( 598 gclient_scm.scm.SVN._CaptureInfo(
598 [], join(self.base_path, ".")).AndReturn(file_info) 599 [], join(self.base_path, ".")).AndReturn(file_info)
599 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 600 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
600 ).AndReturn(file_info) 601 ).AndReturn(file_info)
601 602
602 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 603 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
603 ).AndReturn({'Revision': 100}) 604 ).AndReturn({'Revision': 100})
604 605
605 self.mox.ReplayAll() 606 self.mox.ReplayAll()
(...skipping 14 matching lines...) Expand all
620 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 621 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
621 ).AndReturn('1.5.1') 622 ).AndReturn('1.5.1')
622 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) 623 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True)
623 624
624 # Verify no locked files. 625 # Verify no locked files.
625 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') 626 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.')
626 ).AndReturn([]) 627 ).AndReturn([])
627 628
628 # Now we fall back on scm.update(). 629 # Now we fall back on scm.update().
629 files_list = self.mox.CreateMockAnything() 630 files_list = self.mox.CreateMockAnything()
630 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
631 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 631 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
632 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
633 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(False)
632 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 634 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
633 gclient_scm.scm.SVN._CaptureInfo( 635 gclient_scm.scm.SVN._CaptureInfo(
634 [], join(self.base_path, '.')).AndReturn(file_info) 636 [], join(self.base_path, '.')).AndReturn(file_info)
635 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 637 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
636 ).AndReturn(file_info) 638 ).AndReturn(file_info)
637 639
638 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 640 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
639 ).AndReturn({'Revision': 100}) 641 ).AndReturn({'Revision': 100})
640 642
641 self.mox.ReplayAll() 643 self.mox.ReplayAll()
642 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 644 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
643 relpath=self.relpath) 645 relpath=self.relpath)
644 scm.updatesingle(options, ['DEPS'], files_list) 646 scm.updatesingle(options, ['DEPS'], files_list)
645 self.checkstdout('\n_____ %s at 42\n' % self.relpath) 647 self.checkstdout('\n_____ %s at 42\n' % self.relpath)
646 648
647 def testUpdateGit(self): 649 def testUpdateGit(self):
648 options = self.Options(verbose=True) 650 options = self.Options(verbose=True)
649 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') 651 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
650 gclient_scm.os.path.exists(file_path).AndReturn(True) 652 gclient_scm.os.path.exists(file_path).AndReturn(False)
653 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
654 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
655 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(True)
656 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
657 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
658
659 self.mox.ReplayAll()
660 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
661 relpath=self.relpath)
662 error = ('%s contains a git checkout. Delete the directory and try again.'
663 % self.base_path)
664 self.assertRaisesError(error, scm.update, options, None, [])
665
666 def testUpdateGitForce(self):
667 options = self.Options(verbose=True, force=True)
668 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
669 gclient_scm.os.path.exists(file_path).AndReturn(False)
670 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
671 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
672 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(True)
673 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
674 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
675 gclient_scm.gclient_utils.rmtree(self.base_path)
676 gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
677 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
678 ).AndReturn('1.5.1')
679 gclient_scm.scm.SVN.RunAndGetFileList(
680 options.verbose,
681 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
682 cwd=self.root_dir,
683 file_list=[])
684 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
685 ).AndReturn({'Revision': 100})
651 686
652 self.mox.ReplayAll() 687 self.mox.ReplayAll()
653 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 688 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
654 relpath=self.relpath) 689 relpath=self.relpath)
655 file_list = [] 690 file_list = []
656 scm.update(options, self.args, file_list) 691 scm.update(options, None, file_list)
692
693 def testUpdateGitSvn(self):
694 options = self.Options(verbose=True)
695 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
696 gclient_scm.os.path.exists(file_path).AndReturn(False)
697 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
698 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGit', True)
699 gclient_scm.scm.GIT.IsGit(self.base_path).AndReturn(True)
700 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
701 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True)
702 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
703 gclient_scm.scm.GIT.Capture(['config', '--local', '--get',
704 'svn-remote.svn.url'],
705 cwd=self.base_path).AndReturn(self.url)
706
707 self.mox.ReplayAll()
708 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
709 relpath=self.relpath)
710 file_list = []
711 scm.update(options, [], file_list)
657 self.checkstdout( 712 self.checkstdout(
658 ('________ found .git directory; skipping %s\n' % self.relpath)) 713 ('\n_____ %s looks like a git-svn checkout. Skipping.\n' % self.relpath)
714 )
659 715
660 def testUpdateHg(self): 716 def testUpdateHg(self):
661 options = self.Options(verbose=True) 717 options = self.Options(verbose=True)
662 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
663 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) 718 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True)
664 719
665 self.mox.ReplayAll() 720 self.mox.ReplayAll()
666 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 721 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
667 relpath=self.relpath) 722 relpath=self.relpath)
668 file_list = [] 723 file_list = []
669 scm.update(options, self.args, file_list) 724 scm.update(options, self.args, file_list)
670 self.checkstdout( 725 self.checkstdout(
671 ('________ found .hg directory; skipping %s\n' % self.relpath)) 726 ('________ found .hg directory; skipping %s\n' % self.relpath))
672 727
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 self.assertEquals(git_svn_scm.GetUsableRev('3', options), 1299 self.assertEquals(git_svn_scm.GetUsableRev('3', options),
1245 self.fake_hash_2) 1300 self.fake_hash_2)
1246 # Given a git sha1 with a git-svn checkout, it should be used as is. 1301 # Given a git sha1 with a git-svn checkout, it should be used as is.
1247 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), 1302 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options),
1248 self.fake_hash_1) 1303 self.fake_hash_1)
1249 # We currently check for seemingly valid SVN revisions by assuming 6 digit 1304 # We currently check for seemingly valid SVN revisions by assuming 6 digit
1250 # numbers, so assure that numeric revs >= 1000000 don't work. 1305 # numbers, so assure that numeric revs >= 1000000 don't work.
1251 self.assertRaises(gclient_scm.gclient_utils.Error, 1306 self.assertRaises(gclient_scm.gclient_utils.Error,
1252 git_svn_scm.GetUsableRev, too_big, options) 1307 git_svn_scm.GetUsableRev, too_big, options)
1253 1308
1309 def testUpdateNoDotGit(self):
1310 options = self.Options()
1311
1312 #self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
1313 #gclient_scm.scm.GIT.Capture(['--version'], '.').AndReturn('version 1.6.6')
borenet 2014/02/28 16:52:23 I'm really confused by this; when I run all of the
1314 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1315 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1316 ).AndReturn(False)
1317
1318 self.mox.ReplayAll()
1319 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1320 relpath=self.relpath)
1321 error = ('\n____ %s at refs/remotes/origin/master\n\tPath is not a git '
1322 'repo. No .git dir.\n\tTo resolve:\n\t\trm -rf %s\n\tAnd run '
1323 'gclient sync again\n\tOr run with --force\n' % (self.relpath,
1324 self.relpath))
1325 self.assertRaisesError(error, scm.update, options, None, [])
1326
1327 def testUpdateNoDotGitForce(self):
1328 options = self.Options(force=True)
1329
1330 #self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
1331 #gclient_scm.scm.GIT.Capture(['--version'], '.').AndReturn('version 1.6.6')
1332 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1333 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1334 ).AndReturn(False)
1335 gclient_scm.gclient_utils.rmtree(self.base_path)
1336 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
1337 # pylint: disable=E1120
1338 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
1339 options)
1340 # pylint: disable=E1120
1341 self.mox.StubOutWithMock(gclient_scm.GitWrapper, 'UpdateSubmoduleConfig',
1342 True)
1343 gclient_scm.GitWrapper.UpdateSubmoduleConfig()
1344 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
1345 gclient_scm.subprocess2.check_output(['git', 'ls-files'],
1346 cwd=self.base_path,
1347 stderr=gclient_scm.subprocess2.VOID,
1348 ).AndReturn('')
1349 gclient_scm.subprocess2.check_output(
1350 ['git', 'rev-parse', '--verify', 'HEAD'],
1351 cwd=self.base_path,
1352 stderr=gclient_scm.subprocess2.VOID,
1353 ).AndReturn('')
1354
1355 self.mox.ReplayAll()
1356 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1357 relpath=self.relpath)
1358 scm.update(options, None, [])
1359 self.checkstdout('_____ Conflicting directory found in %s. Removing.\n\n'
1360 % self.base_path)
1361
1254 1362
1255 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): 1363 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
1256 def testUpdateUpdate(self): 1364 def testUpdateUpdate(self):
1257 if not self.enabled: 1365 if not self.enabled:
1258 return 1366 return
1259 options = self.Options() 1367 options = self.Options()
1260 expected_file_list = [] 1368 expected_file_list = []
1261 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1369 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1262 relpath=self.relpath) 1370 relpath=self.relpath)
1263 file_list = [] 1371 file_list = []
1264 options.revision = 'unmanaged' 1372 options.revision = 'unmanaged'
1265 scm.update(options, (), file_list) 1373 scm.update(options, (), file_list)
1266 self.assertEquals(file_list, expected_file_list) 1374 self.assertEquals(file_list, expected_file_list)
1267 self.assertEquals(scm.revinfo(options, (), None), 1375 self.assertEquals(scm.revinfo(options, (), None),
1268 '069c602044c5388d2d15c3f875b057c852003458') 1376 '069c602044c5388d2d15c3f875b057c852003458')
1269 self.checkstdout('________ unmanaged solution; skipping .\n') 1377 self.checkstdout('________ unmanaged solution; skipping .\n')
1270 1378
1271 1379
1272 if __name__ == '__main__': 1380 if __name__ == '__main__':
1273 if '-v' in sys.argv: 1381 if '-v' in sys.argv:
1274 logging.basicConfig( 1382 logging.basicConfig(
1275 level=logging.DEBUG, 1383 level=logging.DEBUG,
1276 format='%(asctime).19s %(levelname)s %(filename)s:' 1384 format='%(asctime).19s %(levelname)s %(filename)s:'
1277 '%(lineno)s %(message)s') 1385 '%(lineno)s %(message)s')
1278 unittest.main() 1386 unittest.main()
1279 1387
1280 # vim: ts=2:sw=2:tw=80:et: 1388 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « scm.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698