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

Side by Side Diff: tests/gclient_scm_test.py

Issue 9348054: If --force is specified when updating, remove unversioned directories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' 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
« gclient_scm.py ('K') | « 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) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 # Verify no locked files. 360 # Verify no locked files.
361 dotted_path = join(self.base_path, '.') 361 dotted_path = join(self.base_path, '.')
362 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 362 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
363 363
364 # Checkout or update. 364 # Checkout or update.
365 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 365 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
366 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 366 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
367 # Cheat a bit here. 367 # Cheat a bit here.
368 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 368 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
369 ).AndReturn(file_info) 369 ).AndReturn(file_info)
370 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path).AndReturn([])
371 gclient_scm.scm.SVN.Capture(['--version'], None
372 ).AndReturn('svn, version 1.5.1 (r32289)')
373
370 additional_args = [] 374 additional_args = []
371 if options.manually_grab_svn_rev: 375 if options.manually_grab_svn_rev:
372 additional_args = ['--revision', str(file_info['Revision'])] 376 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']) 377 additional_args.extend(['--force', '--ignore-externals'])
376 files_list = [] 378 files_list = []
377 gclient_scm.scm.SVN.RunAndGetFileList( 379 gclient_scm.scm.SVN.RunAndGetFileList(
380 options.verbose,
381 ['update', self.base_path] + additional_args,
382 cwd=self.root_dir, file_list=files_list)
383
384 self.mox.ReplayAll()
385 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
386 relpath=self.relpath)
387 scm.update(options, (), files_list)
388
389 def testUpdateNoForce(self):
390 options = self.Options(verbose=True)
391
392 file_info = {
393 'Repository Root': 'blah',
394 'URL': self.url,
395 'UUID': 'ABC',
396 'Revision': 42,
397 }
398 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
399 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
400
401 # Create an untracked file.
402 dotted_path = join(self.base_path, '.')
403 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn(
404 [['? ', 'foo']])
405
406 # Checkout or update.
407 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
408 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
409 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
410 ).AndReturn(file_info)
411
412 self.mox.ReplayAll()
413 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
414 relpath=self.relpath)
415 files_list = []
416 scm.update(options, (), files_list)
417 self.checkstdout('\n_____ %s at 42\n' % self.relpath)
418
419 def testUpdateForce(self):
420 options = self.Options(verbose=True)
421 options.force = True
422
423 file_info = {
424 'Repository Root': 'blah',
425 'URL': self.url,
426 'UUID': 'ABC',
427 'Revision': 42,
428 }
429 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
430 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
431
432 # Create an untracked file.
433 dotted_path = join(self.base_path, '.')
434 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
435 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
436
437 # Checkout or update.
438 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
439 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
440 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
441 ).AndReturn(file_info)
442 gclient_scm.scm.SVN.Capture(['--version'], None
443 ).AndReturn('svn, version 1.5.1 (r32289)')
444
445 # Confirm that the untracked file is removed.
446 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path
447 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
448 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True)
449 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False)
450 gclient_scm.gclient_utils.RemoveDirectory(join(self.base_path, 'dir'))
451
452 additional_args = []
453 if options.manually_grab_svn_rev:
454 additional_args = ['--revision', str(file_info['Revision'])]
455 additional_args.extend(['--force', '--ignore-externals'])
456 files_list = []
457 gclient_scm.scm.SVN.RunAndGetFileList(
378 options.verbose, 458 options.verbose,
379 ['update', self.base_path] + additional_args, 459 ['update', self.base_path] + additional_args,
380 cwd=self.root_dir, file_list=files_list) 460 cwd=self.root_dir, file_list=files_list)
381 461
382 self.mox.ReplayAll() 462 self.mox.ReplayAll()
383 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 463 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
384 relpath=self.relpath) 464 relpath=self.relpath)
385 scm.update(options, (), files_list) 465 scm.update(options, (), files_list)
466 self.checkstdout('\n_____ removing unversioned directory dir\n')
386 467
387 def testUpdateSingleCheckout(self): 468 def testUpdateSingleCheckout(self):
388 options = self.Options(verbose=True) 469 options = self.Options(verbose=True)
389 file_info = { 470 file_info = {
390 'URL': self.url, 471 'URL': self.url,
391 'Revision': 42, 472 'Revision': 42,
392 } 473 }
393 474
394 # Checks to make sure that we support svn co --depth. 475 # Checks to make sure that we support svn co --depth.
395 gclient_scm.scm.SVN.current_version = None 476 gclient_scm.scm.SVN.current_version = None
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 file_list = [] 969 file_list = []
889 scm.update(options, (), file_list) 970 scm.update(options, (), file_list)
890 self.assertEquals(file_list, expected_file_list) 971 self.assertEquals(file_list, expected_file_list)
891 self.assertEquals(scm.revinfo(options, (), None), 972 self.assertEquals(scm.revinfo(options, (), None),
892 'a7142dc9f0009350b96a11f372b6ea658592aa95') 973 'a7142dc9f0009350b96a11f372b6ea658592aa95')
893 self.checkstdout( 974 self.checkstdout(
894 '\n_____ . at refs/heads/master\n' 975 '\n_____ . at refs/heads/master\n'
895 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' 976 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
896 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') 977 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n')
897 978
979 def testUpdateNoForce(self):
980 if not self.enabled:
981 return
982 options = self.Options()
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_____ . at refs/heads/master\n'
999 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
1000 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n')
1001
1002 def testUpdateForce(self):
1003 if not self.enabled:
1004 return
1005 options = self.Options()
1006 options.force = True
1007
1008 dir_path = join(self.base_path, 'dir')
1009 os.mkdir(dir_path)
1010 open(join(dir_path, 'nested'), 'w').writelines('new\n')
1011
1012 file_path = join(self.base_path, 'file')
1013 open(file_path, 'w').writelines('new\n')
1014
1015 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1016 relpath=self.relpath)
1017 file_list = []
1018 scm.update(options, (), file_list)
1019 self.assert_(not gclient_scm.os.path.isdir(dir_path))
1020 self.assert_(gclient_scm.os.path.isfile(file_path))
1021 self.checkstdout(
1022 '\n________ running \'git reset --hard HEAD\' in \'%s\''
1023 '\nHEAD is now at 069c602 A and B\n'
1024 '\n_____ . at refs/heads/master\n'
1025 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
1026 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n'
1027 '\n_____ removing unversioned directory dir/\n' % join(self.root_dir,
1028 '.'))
1029
898 def testUpdateUnstagedConflict(self): 1030 def testUpdateUnstagedConflict(self):
899 if not self.enabled: 1031 if not self.enabled:
900 return 1032 return
901 options = self.Options() 1033 options = self.Options()
902 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 1034 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
903 relpath=self.relpath) 1035 relpath=self.relpath)
904 file_path = join(self.base_path, 'b') 1036 file_path = join(self.base_path, 'b')
905 open(file_path, 'w').writelines('conflict\n') 1037 open(file_path, 'w').writelines('conflict\n')
906 try: 1038 try:
907 scm.update(options, (), []) 1039 scm.update(options, (), [])
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 1275
1144 if __name__ == '__main__': 1276 if __name__ == '__main__':
1145 if '-v' in sys.argv: 1277 if '-v' in sys.argv:
1146 logging.basicConfig( 1278 logging.basicConfig(
1147 level=logging.DEBUG, 1279 level=logging.DEBUG,
1148 format='%(asctime).19s %(levelname)s %(filename)s:' 1280 format='%(asctime).19s %(levelname)s %(filename)s:'
1149 '%(lineno)s %(message)s') 1281 '%(lineno)s %(message)s')
1150 unittest.main() 1282 unittest.main()
1151 1283
1152 # vim: ts=2:sw=2:tw=80:et: 1284 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« gclient_scm.py ('K') | « gclient_scm.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698