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

Side by Side Diff: tests/gclient_scm_test.py

Issue 9401011: Revert r121986 "If both -f and -D are specified when updating, remove all untracked 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
« 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) 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.
11 from os import rename 11 from os import rename
12 from shutil import rmtree 12 from shutil import rmtree
(...skipping 63 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
87 86
88 def Options(self, *args, **kwargs): 87 def Options(self, *args, **kwargs):
89 return self.OptionsObject(*args, **kwargs) 88 return self.OptionsObject(*args, **kwargs)
90 89
91 def setUp(self): 90 def setUp(self):
92 BaseTestCase.setUp(self) 91 BaseTestCase.setUp(self)
93 self.url = self.SvnUrl() 92 self.url = self.SvnUrl()
94 93
95 def testDir(self): 94 def testDir(self):
96 members = [ 95 members = [
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 # Verify no locked files. 360 # Verify no locked files.
362 dotted_path = join(self.base_path, '.') 361 dotted_path = join(self.base_path, '.')
363 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) 362 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([])
364 363
365 # Checkout or update. 364 # Checkout or update.
366 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 365 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
367 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) 366 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
368 # Cheat a bit here. 367 # Cheat a bit here.
369 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None 368 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
370 ).AndReturn(file_info) 369 ).AndReturn(file_info)
371 gclient_scm.scm.SVN.Capture(['--version'], None
372 ).AndReturn('svn, version 1.5.1 (r32289)')
373
374 additional_args = [] 370 additional_args = []
375 if options.manually_grab_svn_rev: 371 if options.manually_grab_svn_rev:
376 additional_args = ['--revision', str(file_info['Revision'])] 372 additional_args = ['--revision', str(file_info['Revision'])]
373 gclient_scm.scm.SVN.Capture(['--version'], None
374 ).AndReturn('svn, version 1.5.1 (r32289)')
377 additional_args.extend(['--force', '--ignore-externals']) 375 additional_args.extend(['--force', '--ignore-externals'])
378 files_list = [] 376 files_list = []
379 gclient_scm.scm.SVN.RunAndGetFileList( 377 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 testUpdateForceNoDeleteUnversionedTrees(self):
390 options = self.Options(verbose=True)
391 options.force = True
392
393 file_info = {
394 'Repository Root': 'blah',
395 'URL': self.url,
396 'UUID': 'ABC',
397 'Revision': 42,
398 }
399 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
400 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
401
402 # Create an untracked file and directory.
403 dotted_path = join(self.base_path, '.')
404 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
405 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
406
407 # Checkout or update.
408 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
409 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
410 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
411 ).AndReturn(file_info)
412 gclient_scm.scm.SVN.Capture(['--version'], None
413 ).AndReturn('svn, version 1.5.1 (r32289)')
414
415 additional_args = []
416 if options.manually_grab_svn_rev:
417 additional_args = ['--revision', str(file_info['Revision'])]
418 additional_args.extend(['--force', '--ignore-externals'])
419 files_list = []
420 gclient_scm.scm.SVN.RunAndGetFileList(
421 options.verbose,
422 ['update', self.base_path] + additional_args,
423 cwd=self.root_dir, file_list=files_list)
424
425 self.mox.ReplayAll()
426 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
427 relpath=self.relpath)
428 scm.update(options, (), files_list)
429
430 def testUpdateForceDeleteUnversionedTrees(self):
431 options = self.Options(verbose=True)
432 options.force = True
433 options.delete_unversioned_trees = True
434
435 file_info = {
436 'Repository Root': 'blah',
437 'URL': self.url,
438 'UUID': 'ABC',
439 'Revision': 42,
440 }
441 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False)
442 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False)
443
444 # Create an untracked file and directory.
445 dotted_path = join(self.base_path, '.')
446 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path
447 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
448
449 # Checkout or update.
450 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
451 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info)
452 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None
453 ).AndReturn(file_info)
454 gclient_scm.scm.SVN.Capture(['--version'], None
455 ).AndReturn('svn, version 1.5.1 (r32289)')
456
457 # Confirm that the untracked file is removed.
458 gclient_scm.scm.SVN.CaptureStatus(None, self.base_path
459 ).AndReturn([['? ', 'dir'], ['? ', 'file']])
460 gclient_scm.os.path.isdir(join(self.base_path, 'dir')).AndReturn(True)
461 gclient_scm.os.path.isdir(join(self.base_path, 'file')).AndReturn(False)
462 gclient_scm.gclient_utils.RemoveDirectory(join(self.base_path, 'dir'))
463
464 additional_args = []
465 if options.manually_grab_svn_rev:
466 additional_args = ['--revision', str(file_info['Revision'])]
467 additional_args.extend(['--force', '--ignore-externals'])
468 files_list = []
469 gclient_scm.scm.SVN.RunAndGetFileList(
470 options.verbose, 378 options.verbose,
471 ['update', self.base_path] + additional_args, 379 ['update', self.base_path] + additional_args,
472 cwd=self.root_dir, file_list=files_list) 380 cwd=self.root_dir, file_list=files_list)
473 381
474 self.mox.ReplayAll() 382 self.mox.ReplayAll()
475 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 383 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
476 relpath=self.relpath) 384 relpath=self.relpath)
477 scm.update(options, (), files_list) 385 scm.update(options, (), files_list)
478 self.checkstdout('\n_____ removing unversioned directory dir\n')
479 386
480 def testUpdateSingleCheckout(self): 387 def testUpdateSingleCheckout(self):
481 options = self.Options(verbose=True) 388 options = self.Options(verbose=True)
482 file_info = { 389 file_info = {
483 'URL': self.url, 390 'URL': self.url,
484 'Revision': 42, 391 'Revision': 42,
485 } 392 }
486 393
487 # Checks to make sure that we support svn co --depth. 394 # Checks to make sure that we support svn co --depth.
488 gclient_scm.scm.SVN.current_version = None 395 gclient_scm.scm.SVN.current_version = None
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 class OptionsObject(object): 582 class OptionsObject(object):
676 def __init__(self, verbose=False, revision=None): 583 def __init__(self, verbose=False, revision=None):
677 self.verbose = verbose 584 self.verbose = verbose
678 self.revision = revision 585 self.revision = revision
679 self.manually_grab_svn_rev = True 586 self.manually_grab_svn_rev = True
680 self.deps_os = None 587 self.deps_os = None
681 self.force = False 588 self.force = False
682 self.reset = False 589 self.reset = False
683 self.nohooks = False 590 self.nohooks = False
684 self.merge = False 591 self.merge = False
685 self.delete_unversioned_trees = False
686 592
687 sample_git_import = """blob 593 sample_git_import = """blob
688 mark :1 594 mark :1
689 data 6 595 data 6
690 Hello 596 Hello
691 597
692 blob 598 blob
693 mark :2 599 mark :2
694 data 4 600 data 4
695 Bye 601 Bye
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 file_list = [] 888 file_list = []
983 scm.update(options, (), file_list) 889 scm.update(options, (), file_list)
984 self.assertEquals(file_list, expected_file_list) 890 self.assertEquals(file_list, expected_file_list)
985 self.assertEquals(scm.revinfo(options, (), None), 891 self.assertEquals(scm.revinfo(options, (), None),
986 'a7142dc9f0009350b96a11f372b6ea658592aa95') 892 'a7142dc9f0009350b96a11f372b6ea658592aa95')
987 self.checkstdout( 893 self.checkstdout(
988 '\n_____ . at refs/heads/master\n' 894 '\n_____ . at refs/heads/master\n'
989 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n' 895 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
990 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n') 896 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n')
991 897
992 def testUpdateForceNoDeleteUnversionedTrees(self):
993 if not self.enabled:
994 return
995 options = self.Options()
996 options.force = True
997
998 dir_path = join(self.base_path, 'c')
999 os.mkdir(dir_path)
1000 open(join(dir_path, 'nested'), 'w').writelines('new\n')
1001
1002 file_path = join(self.base_path, 'file')
1003 open(file_path, 'w').writelines('new\n')
1004
1005 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1006 relpath=self.relpath)
1007 file_list = []
1008 scm.update(options, (), file_list)
1009 self.assert_(gclient_scm.os.path.isdir(dir_path))
1010 self.assert_(gclient_scm.os.path.isfile(file_path))
1011 self.checkstdout(
1012 '\n________ running \'git reset --hard HEAD\' in \'%s\''
1013 '\nHEAD is now at 069c602 A and B\n'
1014 '\n_____ . at refs/heads/master\n'
1015 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
1016 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n'
1017 % join(self.root_dir, '.'))
1018
1019 def testUpdateForceDeleteUnversionedTrees(self):
1020 if not self.enabled:
1021 return
1022 options = self.Options()
1023 options.force = True
1024 options.delete_unversioned_trees = True
1025
1026 dir_path = join(self.base_path, 'dir')
1027 os.mkdir(dir_path)
1028 open(join(dir_path, 'nested'), 'w').writelines('new\n')
1029
1030 file_path = join(self.base_path, 'file')
1031 open(file_path, 'w').writelines('new\n')
1032
1033 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1034 relpath=self.relpath)
1035 file_list = []
1036 scm.update(options, (), file_list)
1037 self.assert_(not gclient_scm.os.path.isdir(dir_path))
1038 self.assert_(gclient_scm.os.path.isfile(file_path))
1039 self.checkstdout(
1040 '\n________ running \'git reset --hard HEAD\' in \'%s\''
1041 '\nHEAD is now at 069c602 A and B\n'
1042 '\n_____ . at refs/heads/master\n'
1043 'Updating 069c602..a7142dc\nFast-forward\n a | 1 +\n b | 1 +\n'
1044 ' 2 files changed, 2 insertions(+), 0 deletions(-)\n\n'
1045 '\n_____ removing unversioned directory dir/\n' % join(self.root_dir,
1046 '.'))
1047
1048 def testUpdateUnstagedConflict(self): 898 def testUpdateUnstagedConflict(self):
1049 if not self.enabled: 899 if not self.enabled:
1050 return 900 return
1051 options = self.Options() 901 options = self.Options()
1052 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, 902 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir,
1053 relpath=self.relpath) 903 relpath=self.relpath)
1054 file_path = join(self.base_path, 'b') 904 file_path = join(self.base_path, 'b')
1055 open(file_path, 'w').writelines('conflict\n') 905 open(file_path, 'w').writelines('conflict\n')
1056 try: 906 try:
1057 scm.update(options, (), []) 907 scm.update(options, (), [])
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 1155
1306 if __name__ == '__main__': 1156 if __name__ == '__main__':
1307 if '-v' in sys.argv: 1157 if '-v' in sys.argv:
1308 logging.basicConfig( 1158 logging.basicConfig(
1309 level=logging.DEBUG, 1159 level=logging.DEBUG,
1310 format='%(asctime).19s %(levelname)s %(filename)s:' 1160 format='%(asctime).19s %(levelname)s %(filename)s:'
1311 '%(lineno)s %(message)s') 1161 '%(lineno)s %(message)s')
1312 unittest.main() 1162 unittest.main()
1313 1163
1314 # vim: ts=2:sw=2:tw=80:et: 1164 # 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