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

Side by Side Diff: tests/gclient_scm_test.py

Issue 225403015: gclient: Actually move or delete mismatched checkouts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Only delete directory on the bots, otherwise just move it, even with --force Created 6 years, 7 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') | 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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 options = self.Options(verbose=True) 639 options = self.Options(verbose=True)
640 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') 640 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
641 gclient_scm.os.path.exists(file_path).AndReturn(False) 641 gclient_scm.os.path.exists(file_path).AndReturn(False)
642 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 642 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
643 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) 643 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
644 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) 644 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
645 error = gclient_scm.subprocess2.CalledProcessError( 645 error = gclient_scm.subprocess2.CalledProcessError(
646 1, 'cmd', '/cwd', 'stdout', 'stderr') 646 1, 'cmd', '/cwd', 'stdout', 'stderr')
647 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error) 647 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
648 648
649 bad_scm_path = os.path.join(self.root_dir, '_bad_scm',
650 os.path.dirname(self.relpath))
651 gclient_scm.os.makedirs(bad_scm_path)
652 dest_path = os.path.join(bad_scm_path,
653 os.path.basename(self.relpath) + 'ABCD')
654 self.mox.StubOutWithMock(gclient_scm.tempfile, 'mkdtemp', True)
655 gclient_scm.tempfile.mkdtemp(
656 prefix=os.path.basename(self.relpath),
657 dir=os.path.join(self.root_dir, '_bad_scm',
658 os.path.dirname(self.relpath))).AndReturn(dest_path)
659 self.mox.StubOutWithMock(gclient_scm.shutil, 'move', True)
660 gclient_scm.shutil.move(self.base_path, dest_path)
649 gclient_scm.os.path.exists(self.root_dir).AndReturn(True) 661 gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
650 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 662 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
651 ).AndReturn('1.5.1') 663 ).AndReturn('1.5.1')
652 gclient_scm.scm.SVN.RunAndGetFileList( 664 gclient_scm.scm.SVN.RunAndGetFileList(
653 options.verbose, 665 options.verbose,
654 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], 666 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'],
655 cwd=self.root_dir, 667 cwd=self.root_dir,
656 file_list=[]) 668 file_list=[])
657 669
658 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 670 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
659 ).AndReturn({'Revision': 100}) 671 ).AndReturn({'Revision': 100})
660 672
661 self.mox.ReplayAll() 673 self.mox.ReplayAll()
662 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 674 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
663 relpath=self.relpath) 675 relpath=self.relpath)
664 scm.update(options, None, []) 676 scm.update(options, None, [])
677 self.checkstdout('_____ Conflicting directory found in %s. Moving to %s.\n'
678 % (self.base_path, dest_path))
665 679
666 def testUpdateGitForce(self): 680 def testUpdateGitForce(self):
667 options = self.Options(verbose=True, force=True) 681 options = self.Options(verbose=True, force=True)
668 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') 682 old_environ = dict(gclient_scm.os.environ)
669 gclient_scm.os.path.exists(file_path).AndReturn(False) 683 gclient_scm.os.environ['CHROME_HEADLESS'] = '1'
borenet 2014/05/05 20:09:52 This seems gross; is there a better way?
iannucci 2014/05/05 20:18:11 Hm. I think mox could do this for you, but I'd hav
670 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 684 try:
671 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) 685 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
672 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) 686 gclient_scm.os.path.exists(file_path).AndReturn(False)
673 error = gclient_scm.subprocess2.CalledProcessError( 687 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
674 1, 'cmd', '/cwd', 'stdout', 'stderr') 688 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
675 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error) 689 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False)
676 gclient_scm.os.path.exists(self.root_dir).AndReturn(True) 690 error = gclient_scm.subprocess2.CalledProcessError(
677 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None 691 1, 'cmd', '/cwd', 'stdout', 'stderr')
678 ).AndReturn('1.5.1') 692 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error)
679 gclient_scm.scm.SVN.RunAndGetFileList( 693 gclient_scm.gclient_utils.rmtree(self.base_path)
680 options.verbose, 694 gclient_scm.os.path.exists(self.root_dir).AndReturn(True)
681 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], 695 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None
682 cwd=self.root_dir, 696 ).AndReturn('1.5.1')
683 file_list=[]) 697 gclient_scm.scm.SVN.RunAndGetFileList(
684 698 options.verbose,
685 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' 699 ['checkout', self.url, self.base_path, '--force',
686 ).AndReturn({'Revision': 100}) 700 '--ignore-externals'],
687 701 cwd=self.root_dir,
688 self.mox.ReplayAll() 702 file_list=[])
689 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 703
690 relpath=self.relpath) 704 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.'
691 file_list = [] 705 ).AndReturn({'Revision': 100})
692 scm.update(options, None, file_list) 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, None, file_list)
712 self.checkstdout('_____ Conflicting directory found in %s. Removing.\n'
713 % self.base_path)
714 finally:
715 gclient_scm.os.environ = old_environ
693 716
694 def testUpdateGitSvn(self): 717 def testUpdateGitSvn(self):
695 options = self.Options(verbose=True) 718 options = self.Options(verbose=True)
696 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') 719 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg')
697 gclient_scm.os.path.exists(file_path).AndReturn(False) 720 gclient_scm.os.path.exists(file_path).AndReturn(False)
698 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 721 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
699 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) 722 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True)
700 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True) 723 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True)
701 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) 724 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True)
702 gclient_scm.scm.GIT.Capture(['config', '--local', '--get', 725 gclient_scm.scm.GIT.Capture(['config', '--local', '--get',
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 self.assertRaises(gclient_scm.gclient_utils.Error, 1313 self.assertRaises(gclient_scm.gclient_utils.Error,
1291 git_svn_scm.GetUsableRev, too_big, options) 1314 git_svn_scm.GetUsableRev, too_big, options)
1292 1315
1293 def testUpdateNoDotGit(self): 1316 def testUpdateNoDotGit(self):
1294 options = self.Options() 1317 options = self.Options()
1295 1318
1296 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 1319 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1297 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 1320 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1298 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') 1321 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1299 ).AndReturn(False) 1322 ).AndReturn(False)
1300
1301 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) 1323 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
1302 # pylint: disable=E1120 1324 # pylint: disable=E1120
1303 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, 1325 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
1304 options) 1326 options)
1305 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) 1327 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True)
1306 gclient_scm.subprocess2.check_output( 1328 gclient_scm.subprocess2.check_output(
1307 ['git', 'ls-files'], cwd=self.base_path, 1329 ['git', 'ls-files'], cwd=self.base_path,
1308 env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('') 1330 env=gclient_scm.scm.GIT.ApplyEnvVars({}), stderr=-1,).AndReturn('')
1309 gclient_scm.subprocess2.check_output( 1331 gclient_scm.subprocess2.check_output(
1310 ['git', 'rev-parse', '--verify', 'HEAD'], 1332 ['git', 'rev-parse', '--verify', 'HEAD'],
1311 cwd=self.base_path, 1333 cwd=self.base_path,
1312 env=gclient_scm.scm.GIT.ApplyEnvVars({}), 1334 env=gclient_scm.scm.GIT.ApplyEnvVars({}),
1313 stderr=-1, 1335 stderr=-1,
1314 ).AndReturn('') 1336 ).AndReturn('')
1315 1337
1316 self.mox.ReplayAll() 1338 self.mox.ReplayAll()
1317 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, 1339 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
1318 relpath=self.relpath) 1340 relpath=self.relpath)
1319 scm.update(options, None, []) 1341 scm.update(options, None, [])
1320 self.checkstdout('\n') 1342 self.checkstdout('\n')
1321 1343
1322 def testUpdateConflict(self): 1344 def testUpdateConflict(self):
1323 options = self.Options() 1345 options = self.Options()
1324 1346
1325 gclient_scm.os.path.exists(self.base_path).AndReturn(True) 1347 gclient_scm.os.path.exists(self.base_path).AndReturn(True)
1326 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) 1348 gclient_scm.os.path.isdir(self.base_path).AndReturn(True)
1327 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') 1349 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git')
1328 ).AndReturn(False) 1350 ).AndReturn(False)
1329
1330 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) 1351 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True)
1331 # pylint: disable=E1120 1352 # pylint: disable=E1120
1332 gclient_scm.GitWrapper._Clone( 1353 gclient_scm.GitWrapper._Clone(
1333 'refs/remotes/origin/master', self.url, options 1354 'refs/remotes/origin/master', self.url, options
1334 ).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None, 1355 ).AndRaise(gclient_scm.subprocess2.CalledProcessError(None, None, None,
1335 None, None)) 1356 None, None))
1336 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_DeleteOrMove', True) 1357 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_DeleteOrMove', True)
1337 gclient_scm.GitWrapper._DeleteOrMove(False) 1358 gclient_scm.GitWrapper._DeleteOrMove(False)
1338 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, 1359 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url,
1339 options) 1360 options)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 1395
1375 if __name__ == '__main__': 1396 if __name__ == '__main__':
1376 if '-v' in sys.argv: 1397 if '-v' in sys.argv:
1377 logging.basicConfig( 1398 logging.basicConfig(
1378 level=logging.DEBUG, 1399 level=logging.DEBUG,
1379 format='%(asctime).19s %(levelname)s %(filename)s:' 1400 format='%(asctime).19s %(levelname)s %(filename)s:'
1380 '%(lineno)s %(message)s') 1401 '%(lineno)s %(message)s')
1381 unittest.main() 1402 unittest.main()
1382 1403
1383 # vim: ts=2:sw=2:tw=80:et: 1404 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« no previous file with comments | « gclient_scm.py ('k') | tests/gclient_smoketest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698