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

Side by Side Diff: tests/gclient_scm_test.py

Issue 9404014: If both -R and -D are specified when updating, remove all untracked directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: If both -R and -D are specified when updating, remove all untracked directories Created 8 years, 10 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 | « gclient_scm.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for gclient_scm.py.""" 6 """Unit tests for gclient_scm.py."""
7 7
8 # pylint: disable=E1103 8 # pylint: disable=E1103
9 9
10 # Import before super_mox to keep valid references. 10 # Import before super_mox to keep valid references.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 def __init__(self, verbose=False, revision=None, force=False): 76 def __init__(self, verbose=False, revision=None, force=False):
77 self.verbose = verbose 77 self.verbose = verbose
78 self.revision = revision 78 self.revision = revision
79 self.manually_grab_svn_rev = True 79 self.manually_grab_svn_rev = True
80 self.deps_os = None 80 self.deps_os = None
81 self.force = force 81 self.force = force
82 self.reset = False 82 self.reset = False
83 self.nohooks = False 83 self.nohooks = False
84 # TODO(maruel): Test --jobs > 1. 84 # TODO(maruel): Test --jobs > 1.
85 self.jobs = 1 85 self.jobs = 1
86 self.delete_unversioned_trees = False
86 87
87 def Options(self, *args, **kwargs): 88 def Options(self, *args, **kwargs):
88 return self.OptionsObject(*args, **kwargs) 89 return self.OptionsObject(*args, **kwargs)
89 90
90 def setUp(self): 91 def setUp(self):
91 BaseTestCase.setUp(self) 92 BaseTestCase.setUp(self)
92 self.url = self.SvnUrl() 93 self.url = self.SvnUrl()
93 94
94 def testDir(self): 95 def testDir(self):
95 members = [ 96 members = [
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 options.force = True 350 options.force = True
350 options.nohooks = False 351 options.nohooks = False
351 file_info = { 352 file_info = {
352 'Repository Root': 'blah', 353 'Repository Root': 'blah',
353 'URL': self.url, 354 'URL': self.url,
354 'UUID': 'ABC', 355 'UUID': 'ABC',
355 'Revision': 42, 356 'Revision': 42,
356 } 357 }
357 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) 358 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
358 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) 359 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
360 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
361
362 # Checkout or update.
363 dotted_path = join(self.base_path, '.')
364 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
359 365
360 # Verify no locked files. 366 # Verify no locked files.
361 dotted_path = join(self.base_path, '.')
362 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 367 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
363 368
364 # Checkout or update.
365 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
366 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
367 # Cheat a bit here. 369 # Cheat a bit here.
368 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 370 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
369 ).AndReturn(file_info) 371 ).AndReturn(file_info)
372
373 # _AddAdditionalUpdateFlags()
374 gclient_scm.scm.SVN.Capture(['--version'], None
375 ).AndReturn('svn, version 1.5.1 (r32289)')
376
370 additional_args = [] 377 additional_args = []
371 if options.manually_grab_svn_rev: 378 if options.manually_grab_svn_rev:
372 additional_args = ['--revision', str(file_info['Revision'])] 379 additional_args = ['--revision', str(file_info['Revision'])]
373 gclient_scm.scm.SVN.Capture(['--version'], None
374 ).AndReturn('svn, version 1.5.1 (r32289)')
375 additional_args.extend(['--force', '--ignore-externals']) 380 additional_args.extend(['--force', '--ignore-externals'])
376 files_list = [] 381 files_list = []
377 gclient_scm.scm.SVN.RunAndGetFileList( 382 gclient_scm.scm.SVN.RunAndGetFileList(
378 options.verbose, 383 options.verbose,
379 ['update', self.base_path] + additional_args, 384 ['update', self.base_path] + additional_args,
380 cwd=self.root_dir, file_list=files_list) 385 cwd=self.root_dir, file_list=files_list)
381 386
382 self.mox.ReplayAll() 387 self.mox.ReplayAll()
383 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 388 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
384 relpath=self.relpath) 389 relpath=self.relpath)
385 scm.update(options, (), files_list) 390 scm.update(options, (), files_list)
386 391
392 def testUpdateReset(self):
393 options = self.Options(verbose=True)
394 options.reset = True
395 file_info = {
396 'Repository Root': 'blah',
397 'URL': self.url,
398 'UUID': 'ABC',
399 'Revision': 42,
400 }
401 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
402 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
403 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
404
405 # Checkout or update.
406 dotted_path = join(self.base_path, '.')
407 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
408
409 # Create an untracked file and directory.
410 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
411 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
412
413 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
414 ).AndReturn(file_info)
415
416 self.mox.ReplayAll()
417 files_list = []
418 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
419 relpath=self.relpath)
420 scm.update(options, (), files_list)
421 self.checkstdout('\n_____ %s at 42\n' % self.relpath)
422
423 def testUpdateResetDeleteUnversionedTrees(self):
424 options = self.Options(verbose=True)
425 options.reset = True
426 options.delete_unversioned_trees = True
427
428 file_info = {
429 'Repository Root': 'blah',
430 'URL': self.url,
431 'UUID': 'ABC',
432 'Revision': 42,
433 }
434 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
435 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
436 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
437
438 # Checkout or update.
439 dotted_path = join(self.base_path, '.')
440 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
441
442 # Create an untracked file and directory.
443 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
444 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
445
446 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
447 ).AndReturn(file_info)
448
449 # Confirm that the untracked file is removed.
450 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path
451 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
452 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True)
453 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False)
454 gclient_scm.os.path.islink(join(self.base_path, 'dir')).AndReturn(False)
455 gclient_scm.gclient_utils.RemoveDirectory(join(self.base_path, 'dir'))
456
457 self.mox.ReplayAll()
458 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
459 relpath=self.relpath)
460 files_list = []
461 scm.update(options, (), files_list)
462 self.checkstdout(
463 ('\n_____ %s at 42\n'
464 '\n_____ removing unversioned directory dir\n') % self.relpath)
465
387 def testUpdateSingleCheckout(self): 466 def testUpdateSingleCheckout(self):
388 options = self.Options(verbose=True) 467 options = self.Options(verbose=True)
389 file_info = { 468 file_info = {
390 'URL': self.url, 469 'URL': self.url,
391 'Revision': 42, 470 'Revision': 42,
392 } 471 }
393 472
394 # Checks to make sure that we support svn co --depth. 473 # Checks to make sure that we support svn co --depth.
395 gclient_scm.scm.SVN.current_version = None 474 gclient_scm.scm.SVN.current_version = None
396 gclient_scm.scm.SVN.Capture(['--version'], None 475 gclient_scm.scm.SVN.Capture(['--version'], None
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 class OptionsObject(object): 661 class OptionsObject(object):
583 def __init__(self, verbose=False, revision=None): 662 def __init__(self, verbose=False, revision=None):
584 self.verbose = verbose 663 self.verbose = verbose
585 self.revision = revision 664 self.revision = revision
586 self.manually_grab_svn_rev = True 665 self.manually_grab_svn_rev = True
587 self.deps_os = None 666 self.deps_os = None
588 self.force = False 667 self.force = False
589 self.reset = False 668 self.reset = False
590 self.nohooks = False 669 self.nohooks = False
591 self.merge = False 670 self.merge = False
671 self.delete_unversioned_trees = False
592 672
593 sample_git_import = """blob 673 sample_git_import = """blob
594 mark :1 674 mark :1
595 data 6 675 data 6
596 Hello 676 Hello
597 677
598 blob 678 blob
599 mark :2 679 mark :2
600 data 4 680 data 4
601 Bye 681 Bye
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 file_list = [] 968 file_list = []
889 scm.update(options, (), file_list) 969 scm.update(options, (), file_list)
890 self.assertEquals(file_list, expected_file_list) 970 self.assertEquals(file_list, expected_file_list)
891 self.assertEquals(scm.revinfo(options, (), None), 971 self.assertEquals(scm.revinfo(options, (), None),
892 'a7142dc9f0009350b96a11f372b6ea658592aa95') 972 'a7142dc9f0009350b96a11f372b6ea658592aa95')
893 self.checkstdout( 973 self.checkstdout(
894 '\n_____ . at refs/heads/master\n' 974 '\n_____ . at refs/heads/master\n'
895 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' 975 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
896 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') 976 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n')
897 977
978 def testUpdateReset(self):
979 if not self.enabled:
980 return
981 options = self.Options()
982 options.reset = True
983
984 dir_path = join(self.base_path, 'c')
985 os.mkdir(dir_path)
986 open(join(dir_path, 'nested'), 'w').writelines('new\n')
987
988 file_path = join(self.base_path, 'file')
989 open(file_path, 'w').writelines('new\n')
990
991 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
992 relpath=self.relpath)
993 file_list = []
994 scm.update(options, (), file_list)
995 self.assert_(gclient_scm.os.path.isdir(dir_path))
996 self.assert_(gclient_scm.os.path.isfile(file_path))
997 self.checkstdout(
998 '\n________ running \'git reset --hard HEAD\' in \'%s\''
999 '\nHEAD is now at 069c602 A and B\n'
1000 '\n_____ . at refs/heads/master\n'
1001 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
1002 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n'
1003 % join(self.root_dir, '.'))
1004
1005 def testUpdateResetDeleteUnversionedTrees(self):
1006 if not self.enabled:
1007 return
1008 options = self.Options()
1009 options.reset = True
1010 options.delete_unversioned_trees = True
1011
1012 dir_path = join(self.base_path, 'dir')
1013 os.mkdir(dir_path)
1014 open(join(dir_path, 'nested'), 'w').writelines('new\n')
1015
1016 file_path = join(self.base_path, 'file')
1017 open(file_path, 'w').writelines('new\n')
1018
1019 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1020 relpath=self.relpath)
1021 file_list = []
1022 scm.update(options, (), file_list)
1023 self.assert_(not gclient_scm.os.path.isdir(dir_path))
1024 self.assert_(gclient_scm.os.path.isfile(file_path))
1025 self.checkstdout(
1026 '\n________ running \'git reset --hard HEAD\' in \'%s\''
1027 '\nHEAD is now at 069c602 A and B\n'
1028 '\n_____ . at refs/heads/master\n'
1029 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
1030 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n'
1031 '\n_____ removing unversioned directory dir/\n' % join(self.root_dir,
1032 '.'))
1033
898 def testUpdateUnstagedConflict(self): 1034 def testUpdateUnstagedConflict(self):
899 if not self.enabled: 1035 if not self.enabled:
900 return 1036 return
901 options = self.Options() 1037 options = self.Options()
902 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1038 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
903 relpath=self.relpath) 1039 relpath=self.relpath)
904 file_path = join(self.base_path, 'b') 1040 file_path = join(self.base_path, 'b')
905 open(file_path, 'w').writelines('conflict\n') 1041 open(file_path, 'w').writelines('conflict\n')
906 try: 1042 try:
907 scm.update(options, (), []) 1043 scm.update(options, (), [])
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 1291
1156 if __name__ == '__main__': 1292 if __name__ == '__main__':
1157 if '-v' in sys.argv: 1293 if '-v' in sys.argv:
1158 logging.basicConfig( 1294 logging.basicConfig(
1159 level=logging.DEBUG, 1295 level=logging.DEBUG,
1160 format='%(asctime).19s %(levelname)s %(filename)s:' 1296 format='%(asctime).19s %(levelname)s %(filename)s:'
1161 '%(lineno)s %(message)s') 1297 '%(lineno)s %(message)s')
1162 unittest.main() 1298 unittest.main()
1163 1299
1164 # vim: ts=2:sw=2:tw=80:et: 1300 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698