 Chromium Code Reviews
 Chromium Code Reviews Issue 183283003:
  Another attempt: gclient: delete mismatching checkouts  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
    
  
    Issue 183283003:
  Another attempt: gclient: delete mismatching checkouts  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools| OLD | NEW | 
|---|---|
| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 def testGITFakeHttpsUrl(self): | 128 def testGITFakeHttpsUrl(self): | 
| 129 self.url = 'git+https://foo' | 129 self.url = 'git+https://foo' | 
| 130 | 130 | 
| 131 self.mox.ReplayAll() | 131 self.mox.ReplayAll() | 
| 132 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 132 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 133 relpath=self.relpath) | 133 relpath=self.relpath) | 
| 134 self.assertEqual(scm.url, 'https://foo') | 134 self.assertEqual(scm.url, 'https://foo') | 
| 135 | 135 | 
| 136 def testRunCommandException(self): | 136 def testRunCommandException(self): | 
| 137 options = self.Options(verbose=False) | 137 options = self.Options(verbose=False) | 
| 138 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 139 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 138 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 140 | 139 | 
| 141 self.mox.ReplayAll() | 140 self.mox.ReplayAll() | 
| 142 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 141 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 143 relpath=self.relpath) | 142 relpath=self.relpath) | 
| 144 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 143 exception = "Unsupported argument(s): %s" % ','.join(self.args) | 
| 145 self.assertRaisesError(exception, scm.RunCommand, | 144 self.assertRaisesError(exception, scm.RunCommand, | 
| 146 'update', options, self.args) | 145 'update', options, self.args) | 
| 147 | 146 | 
| 148 def testRunCommandUnknown(self): | 147 def testRunCommandUnknown(self): | 
| 149 # TODO(maruel): if ever used. | 148 # TODO(maruel): if ever used. | 
| 150 pass | 149 pass | 
| 151 | 150 | 
| 152 def testRevertMissing(self): | 151 def testRevertMissing(self): | 
| 153 options = self.Options(verbose=True) | 152 options = self.Options(verbose=True) | 
| 154 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 153 gclient_scm.os.path.isdir(self.base_path).AndReturn(False) | 
| 155 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 154 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
| 156 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 155 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 
| 157 ).AndReturn('1.5.1') | 156 ).AndReturn('1.5.1') | 
| 158 # It'll to a checkout instead. | 157 # It'll to a checkout instead. | 
| 159 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 160 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 158 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 161 # Checkout. | 159 # Checkout. | 
| 162 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 160 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
| 163 parent = gclient_scm.os.path.dirname(self.base_path) | 161 parent = gclient_scm.os.path.dirname(self.base_path) | 
| 164 gclient_scm.os.path.exists(parent).AndReturn(False) | 162 gclient_scm.os.path.exists(parent).AndReturn(False) | 
| 165 gclient_scm.os.makedirs(parent) | 163 gclient_scm.os.makedirs(parent) | 
| 166 gclient_scm.os.path.exists(parent).AndReturn(True) | 164 gclient_scm.os.path.exists(parent).AndReturn(True) | 
| 167 files_list = self.mox.CreateMockAnything() | 165 files_list = self.mox.CreateMockAnything() | 
| 168 gclient_scm.scm.SVN.RunAndGetFileList( | 166 gclient_scm.scm.SVN.RunAndGetFileList( | 
| 169 options.verbose, | 167 options.verbose, | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 181 self.checkstdout( | 179 self.checkstdout( | 
| 182 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 180 ('\n_____ %s is missing, synching instead\n' % self.relpath)) | 
| 183 | 181 | 
| 184 def testRevertNoDotSvn(self): | 182 def testRevertNoDotSvn(self): | 
| 185 options = self.Options(verbose=True, force=True) | 183 options = self.Options(verbose=True, force=True) | 
| 186 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 184 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | 
| 187 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) | 185 gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(False) | 
| 188 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) | 186 gclient_scm.os.path.isdir(join(self.base_path, '.git')).AndReturn(False) | 
| 189 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) | 187 gclient_scm.os.path.isdir(join(self.base_path, '.hg')).AndReturn(False) | 
| 190 # Checkout. | 188 # Checkout. | 
| 191 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 192 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 189 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 193 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 190 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
| 194 parent = gclient_scm.os.path.dirname(self.base_path) | 191 parent = gclient_scm.os.path.dirname(self.base_path) | 
| 195 gclient_scm.os.path.exists(parent).AndReturn(False) | 192 gclient_scm.os.path.exists(parent).AndReturn(False) | 
| 196 gclient_scm.os.makedirs(parent) | 193 gclient_scm.os.makedirs(parent) | 
| 197 gclient_scm.os.path.exists(parent).AndReturn(True) | 194 gclient_scm.os.path.exists(parent).AndReturn(True) | 
| 198 files_list = self.mox.CreateMockAnything() | 195 files_list = self.mox.CreateMockAnything() | 
| 199 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 196 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 
| 200 ).AndReturn('1.6') | 197 ).AndReturn('1.6') | 
| 201 gclient_scm.scm.SVN.RunAndGetFileList( | 198 gclient_scm.scm.SVN.RunAndGetFileList( | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 | 304 | 
| 308 # TODO(maruel): TEST REVISIONS!!! | 305 # TODO(maruel): TEST REVISIONS!!! | 
| 309 # TODO(maruel): TEST RELOCATE!!! | 306 # TODO(maruel): TEST RELOCATE!!! | 
| 310 def testUpdateCheckout(self): | 307 def testUpdateCheckout(self): | 
| 311 options = self.Options(verbose=True) | 308 options = self.Options(verbose=True) | 
| 312 file_info = gclient_scm.gclient_utils.PrintableObject() | 309 file_info = gclient_scm.gclient_utils.PrintableObject() | 
| 313 file_info.root = 'blah' | 310 file_info.root = 'blah' | 
| 314 file_info.url = self.url | 311 file_info.url = self.url | 
| 315 file_info.uuid = 'ABC' | 312 file_info.uuid = 'ABC' | 
| 316 file_info.revision = 42 | 313 file_info.revision = 42 | 
| 317 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 318 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 314 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 319 # Checkout. | 315 # Checkout. | 
| 320 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 316 gclient_scm.os.path.exists(self.base_path).AndReturn(False) | 
| 321 parent = gclient_scm.os.path.dirname(self.base_path) | 317 parent = gclient_scm.os.path.dirname(self.base_path) | 
| 322 gclient_scm.os.path.exists(parent).AndReturn(False) | 318 gclient_scm.os.path.exists(parent).AndReturn(False) | 
| 323 gclient_scm.os.makedirs(parent) | 319 gclient_scm.os.makedirs(parent) | 
| 324 gclient_scm.os.path.exists(parent).AndReturn(True) | 320 gclient_scm.os.path.exists(parent).AndReturn(True) | 
| 325 files_list = self.mox.CreateMockAnything() | 321 files_list = self.mox.CreateMockAnything() | 
| 326 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 322 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 
| 327 ).AndReturn('1.5.1') | 323 ).AndReturn('1.5.1') | 
| (...skipping 12 matching lines...) Expand all Loading... | |
| 340 def testUpdateUpdate(self): | 336 def testUpdateUpdate(self): | 
| 341 options = self.Options(verbose=True) | 337 options = self.Options(verbose=True) | 
| 342 options.force = True | 338 options.force = True | 
| 343 options.nohooks = False | 339 options.nohooks = False | 
| 344 file_info = { | 340 file_info = { | 
| 345 'Repository Root': 'blah', | 341 'Repository Root': 'blah', | 
| 346 'URL': self.url, | 342 'URL': self.url, | 
| 347 'UUID': 'ABC', | 343 'UUID': 'ABC', | 
| 348 'Revision': 42, | 344 'Revision': 42, | 
| 349 } | 345 } | 
| 350 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 351 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 346 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 347 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 348 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 352 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 349 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 
| 353 | 350 | 
| 354 # Checkout or update. | 351 # Checkout or update. | 
| 355 dotted_path = join(self.base_path, '.') | 352 dotted_path = join(self.base_path, '.') | 
| 356 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 353 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 
| 357 | 354 | 
| 358 # Verify no locked files. | 355 # Verify no locked files. | 
| 359 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | 356 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path).AndReturn([]) | 
| 360 | 357 | 
| 361 # Cheat a bit here. | 358 # Cheat a bit here. | 
| (...skipping 24 matching lines...) Expand all Loading... | |
| 386 | 383 | 
| 387 def testUpdateReset(self): | 384 def testUpdateReset(self): | 
| 388 options = self.Options(verbose=True) | 385 options = self.Options(verbose=True) | 
| 389 options.reset = True | 386 options.reset = True | 
| 390 file_info = { | 387 file_info = { | 
| 391 'Repository Root': 'blah', | 388 'Repository Root': 'blah', | 
| 392 'URL': self.url, | 389 'URL': self.url, | 
| 393 'UUID': 'ABC', | 390 'UUID': 'ABC', | 
| 394 'Revision': 42, | 391 'Revision': 42, | 
| 395 } | 392 } | 
| 396 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 397 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 393 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 394 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 395 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 398 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 396 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 
| 399 | 397 | 
| 400 # Checkout or update. | 398 # Checkout or update. | 
| 401 dotted_path = join(self.base_path, '.') | 399 dotted_path = join(self.base_path, '.') | 
| 402 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 400 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 
| 403 | 401 | 
| 404 # Create an untracked file and directory. | 402 # Create an untracked file and directory. | 
| 405 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 403 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 
| 406 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 404 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 
| 407 | 405 | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 422 options = self.Options(verbose=True) | 420 options = self.Options(verbose=True) | 
| 423 options.reset = True | 421 options.reset = True | 
| 424 options.delete_unversioned_trees = True | 422 options.delete_unversioned_trees = True | 
| 425 | 423 | 
| 426 file_info = { | 424 file_info = { | 
| 427 'Repository Root': 'blah', | 425 'Repository Root': 'blah', | 
| 428 'URL': self.url, | 426 'URL': self.url, | 
| 429 'UUID': 'ABC', | 427 'UUID': 'ABC', | 
| 430 'Revision': 42, | 428 'Revision': 42, | 
| 431 } | 429 } | 
| 432 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 433 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 430 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 431 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 432 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 434 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 433 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 
| 435 | 434 | 
| 436 # Checkout or update. | 435 # Checkout or update. | 
| 437 dotted_path = join(self.base_path, '.') | 436 dotted_path = join(self.base_path, '.') | 
| 438 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 437 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 
| 439 | 438 | 
| 440 # Create an untracked file and directory. | 439 # Create an untracked file and directory. | 
| 441 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 440 gclient_scm.scm.SVN.CaptureStatus(None, dotted_path | 
| 442 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 441 ).AndReturn([['? ', 'dir'], ['? ', 'file']]) | 
| 443 | 442 | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 487 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 
| 489 always=True, | 488 always=True, | 
| 490 cwd=self.root_dir) | 489 cwd=self.root_dir) | 
| 491 gclient_scm.scm.SVN.RunAndGetFileList( | 490 gclient_scm.scm.SVN.RunAndGetFileList( | 
| 492 options.verbose, | 491 options.verbose, | 
| 493 ['update', 'DEPS', '--ignore-externals'], | 492 ['update', 'DEPS', '--ignore-externals'], | 
| 494 cwd=self.base_path, | 493 cwd=self.base_path, | 
| 495 file_list=files_list) | 494 file_list=files_list) | 
| 496 | 495 | 
| 497 # Now we fall back on scm.update(). | 496 # Now we fall back on scm.update(). | 
| 498 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 499 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 497 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 498 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 499 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 500 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 500 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 
| 501 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 501 gclient_scm.scm.SVN._CaptureInfo([], dotted_path).AndReturn(file_info) | 
| 502 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 502 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 
| 503 ).AndReturn(file_info) | 503 ).AndReturn(file_info) | 
| 504 | 504 | 
| 505 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 505 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 
| 506 ).AndReturn({'Revision': 100}) | 506 ).AndReturn({'Revision': 100}) | 
| 507 | 507 | 
| 508 self.mox.ReplayAll() | 508 self.mox.ReplayAll() | 
| 509 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 509 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 558 ['svn', 'checkout', '--depth', 'empty', self.url, self.base_path], | 
| 559 always=True, | 559 always=True, | 
| 560 cwd=self.root_dir) | 560 cwd=self.root_dir) | 
| 561 gclient_scm.scm.SVN.RunAndGetFileList( | 561 gclient_scm.scm.SVN.RunAndGetFileList( | 
| 562 options.verbose, | 562 options.verbose, | 
| 563 ['update', 'DEPS', '--ignore-externals'], | 563 ['update', 'DEPS', '--ignore-externals'], | 
| 564 cwd=self.base_path, | 564 cwd=self.base_path, | 
| 565 file_list=files_list) | 565 file_list=files_list) | 
| 566 | 566 | 
| 567 # Now we fall back on scm.update(). | 567 # Now we fall back on scm.update(). | 
| 568 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 569 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 568 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 569 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 570 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 570 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 571 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 
| 571 gclient_scm.scm.SVN._CaptureInfo( | 572 gclient_scm.scm.SVN._CaptureInfo( | 
| 572 [], join(self.base_path, ".")).AndReturn(file_info) | 573 [], join(self.base_path, ".")).AndReturn(file_info) | 
| 573 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 574 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 
| 574 ).AndReturn(file_info) | 575 ).AndReturn(file_info) | 
| 575 | 576 | 
| 576 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 577 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 
| 577 ).AndReturn({'Revision': 100}) | 578 ).AndReturn({'Revision': 100}) | 
| 578 | 579 | 
| 579 self.mox.ReplayAll() | 580 self.mox.ReplayAll() | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 594 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 595 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | 
| 595 ).AndReturn('1.5.1') | 596 ).AndReturn('1.5.1') | 
| 596 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) | 597 gclient_scm.os.path.exists(join(self.base_path, '.svn')).AndReturn(True) | 
| 597 | 598 | 
| 598 # Verify no locked files. | 599 # Verify no locked files. | 
| 599 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') | 600 gclient_scm.scm.SVN.CaptureStatus(None, join(self.base_path, '.') | 
| 600 ).AndReturn([]) | 601 ).AndReturn([]) | 
| 601 | 602 | 
| 602 # Now we fall back on scm.update(). | 603 # Now we fall back on scm.update(). | 
| 603 files_list = self.mox.CreateMockAnything() | 604 files_list = self.mox.CreateMockAnything() | 
| 604 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 605 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 605 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(False) | 
| 606 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 607 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 606 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 608 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | 
| 607 gclient_scm.scm.SVN._CaptureInfo( | 609 gclient_scm.scm.SVN._CaptureInfo( | 
| 608 [], join(self.base_path, '.')).AndReturn(file_info) | 610 [], join(self.base_path, '.')).AndReturn(file_info) | 
| 609 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 611 gclient_scm.scm.SVN._CaptureInfo([file_info['URL']], None | 
| 610 ).AndReturn(file_info) | 612 ).AndReturn(file_info) | 
| 611 | 613 | 
| 612 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 614 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | 
| 613 ).AndReturn({'Revision': 100}) | 615 ).AndReturn({'Revision': 100}) | 
| 614 | 616 | 
| 615 self.mox.ReplayAll() | 617 self.mox.ReplayAll() | 
| 616 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 618 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 617 relpath=self.relpath) | 619 relpath=self.relpath) | 
| 618 scm.updatesingle(options, ['DEPS'], files_list) | 620 scm.updatesingle(options, ['DEPS'], files_list) | 
| 619 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 621 self.checkstdout('\n_____ %s at 42\n' % self.relpath) | 
| 620 | 622 | 
| 621 def testUpdateGit(self): | 623 def testUpdateGit(self): | 
| 622 options = self.Options(verbose=True) | 624 options = self.Options(verbose=True) | 
| 623 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') | 625 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') | 
| 624 gclient_scm.os.path.exists(file_path).AndReturn(True) | 626 gclient_scm.os.path.exists(file_path).AndReturn(False) | 
| 627 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
| 628 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 629 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 630 error = gclient_scm.subprocess2.CalledProcessError( | |
| 631 1, 'cmd', '/cwd', 'stdout', 'stderr') | |
| 632 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error) | |
| 633 | |
| 634 self.mox.ReplayAll() | |
| 635 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
| 636 relpath=self.relpath) | |
| 637 error = ('Can\'t update/checkout %s if an unversioned directory is ' | |
| 638 'present. Delete the directory and try again.' % self.base_path) | |
| 639 self.assertRaisesError(error, scm.update, options, None, []) | |
| 640 | |
| 641 def testUpdateGitForce(self): | |
| 642 options = self.Options(verbose=True, force=True) | |
| 643 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') | |
| 644 gclient_scm.os.path.exists(file_path).AndReturn(False) | |
| 645 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
| 646 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 647 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(False) | |
| 648 error = gclient_scm.subprocess2.CalledProcessError( | |
| 649 1, 'cmd', '/cwd', 'stdout', 'stderr') | |
| 650 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.').AndRaise(error) | |
| 651 gclient_scm.gclient_utils.rmtree(self.base_path) | |
| 652 gclient_scm.os.path.exists(self.root_dir).AndReturn(True) | |
| 653 gclient_scm.scm.SVN.Capture(['--version', '--quiet'], None | |
| 654 ).AndReturn('1.5.1') | |
| 655 gclient_scm.scm.SVN.RunAndGetFileList( | |
| 656 options.verbose, | |
| 657 ['checkout', self.url, self.base_path, '--force', '--ignore-externals'], | |
| 658 cwd=self.root_dir, | |
| 659 file_list=[]) | |
| 660 | |
| 661 gclient_scm.scm.SVN._CaptureInfo([], self.base_path+'/.' | |
| 662 ).AndReturn({'Revision': 100}) | |
| 625 | 663 | 
| 626 self.mox.ReplayAll() | 664 self.mox.ReplayAll() | 
| 627 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 665 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 628 relpath=self.relpath) | 666 relpath=self.relpath) | 
| 629 file_list = [] | 667 file_list = [] | 
| 630 scm.update(options, self.args, file_list) | 668 scm.update(options, None, file_list) | 
| 669 self.checkstdout('Removing troublesome path %s\n' % self.base_path) | |
| 670 | |
| 671 def testUpdateGitSvn(self): | |
| 672 options = self.Options(verbose=True) | |
| 673 file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.hg') | |
| 674 gclient_scm.os.path.exists(file_path).AndReturn(False) | |
| 675 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
| 676 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'IsGitSvn', True) | |
| 677 gclient_scm.scm.GIT.IsGitSvn(self.base_path).AndReturn(True) | |
| 678 self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) | |
| 679 gclient_scm.scm.GIT.Capture(['config', '--local', '--get', | |
| 680 'svn-remote.svn.url'], | |
| 681 cwd=self.base_path).AndReturn(self.url) | |
| 682 | |
| 683 self.mox.ReplayAll() | |
| 684 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
| 685 relpath=self.relpath) | |
| 686 file_list = [] | |
| 687 scm.update(options, [], file_list) | |
| 631 self.checkstdout( | 688 self.checkstdout( | 
| 632 ('________ found .git directory; skipping %s\n' % self.relpath)) | 689 ('\n_____ %s looks like a git-svn checkout. Skipping.\n' % self.relpath) | 
| 690 ) | |
| 633 | 691 | 
| 634 def testUpdateHg(self): | 692 def testUpdateHg(self): | 
| 635 options = self.Options(verbose=True) | 693 options = self.Options(verbose=True) | 
| 636 gclient_scm.os.path.exists(join(self.base_path, '.git')).AndReturn(False) | |
| 637 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) | 694 gclient_scm.os.path.exists(join(self.base_path, '.hg')).AndReturn(True) | 
| 638 | 695 | 
| 639 self.mox.ReplayAll() | 696 self.mox.ReplayAll() | 
| 640 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 697 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | 
| 641 relpath=self.relpath) | 698 relpath=self.relpath) | 
| 642 file_list = [] | 699 file_list = [] | 
| 643 scm.update(options, self.args, file_list) | 700 scm.update(options, self.args, file_list) | 
| 644 self.checkstdout( | 701 self.checkstdout( | 
| 645 ('________ found .hg directory; skipping %s\n' % self.relpath)) | 702 ('________ found .hg directory; skipping %s\n' % self.relpath)) | 
| 646 | 703 | 
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 1248 self.assertEquals(git_svn_scm.GetUsableRev('3', options), | 
| 1192 self.fake_hash_2) | 1249 self.fake_hash_2) | 
| 1193 # Given a git sha1 with a git-svn checkout, it should be used as is. | 1250 # Given a git sha1 with a git-svn checkout, it should be used as is. | 
| 1194 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), | 1251 self.assertEquals(git_svn_scm.GetUsableRev(self.fake_hash_1, options), | 
| 1195 self.fake_hash_1) | 1252 self.fake_hash_1) | 
| 1196 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 1253 # We currently check for seemingly valid SVN revisions by assuming 6 digit | 
| 1197 # numbers, so assure that numeric revs >= 1000000 don't work. | 1254 # numbers, so assure that numeric revs >= 1000000 don't work. | 
| 1198 self.assertRaises(gclient_scm.gclient_utils.Error, | 1255 self.assertRaises(gclient_scm.gclient_utils.Error, | 
| 1199 git_svn_scm.GetUsableRev, too_big, options) | 1256 git_svn_scm.GetUsableRev, too_big, options) | 
| 1200 | 1257 | 
| 1258 def testUpdateNoDotGit(self): | |
| 1259 options = self.Options() | |
| 1260 | |
| 1261 #self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) | |
| 1262 #gclient_scm.scm.GIT.Capture(['--version'], '.').AndReturn('version 1.6.6') | |
| 
borenet
2014/03/06 14:27:19
I'm still confused about these lines.  The tests f
 
borenet
2014/03/07 21:50:13
Removed these lines in a subsequent patch set.
 | |
| 1263 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
| 1264 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
| 1265 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | |
| 1266 ).AndReturn(False) | |
| 1267 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
| 1268 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | |
| 1269 ).AndReturn(False) | |
| 1270 | |
| 1271 self.mox.ReplayAll() | |
| 1272 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
| 1273 relpath=self.relpath) | |
| 1274 error = ('\n____ %s at refs/remotes/origin/master\n\tPath is not a git ' | |
| 1275 'repo. No .git dir.\n\tTo resolve:\n\t\trm -rf %s\n\tAnd run ' | |
| 1276 'gclient sync again\n\tOr run with --force\n' % (self.relpath, | |
| 1277 self.relpath)) | |
| 1278 self.assertRaisesError(error, scm.update, options, None, []) | |
| 1279 | |
| 1280 def testUpdateNoDotGitForce(self): | |
| 1281 options = self.Options(force=True) | |
| 1282 | |
| 1283 #self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture', True) | |
| 1284 #gclient_scm.scm.GIT.Capture(['--version'], '.').AndReturn('version 1.6.6') | |
| 1285 gclient_scm.os.path.exists(self.base_path).AndReturn(True) | |
| 1286 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
| 1287 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | |
| 1288 ).AndReturn(False) | |
| 1289 gclient_scm.os.path.isdir(self.base_path).AndReturn(True) | |
| 1290 gclient_scm.os.path.exists(os.path.join(self.base_path, '.git') | |
| 1291 ).AndReturn(False) | |
| 1292 gclient_scm.gclient_utils.rmtree(self.base_path) | |
| 1293 self.mox.StubOutWithMock(gclient_scm.GitWrapper, '_Clone', True) | |
| 1294 # pylint: disable=E1120 | |
| 1295 gclient_scm.GitWrapper._Clone('refs/remotes/origin/master', self.url, | |
| 1296 options) | |
| 1297 # pylint: disable=E1120 | |
| 1298 self.mox.StubOutWithMock(gclient_scm.GitWrapper, 'UpdateSubmoduleConfig', | |
| 1299 True) | |
| 1300 gclient_scm.GitWrapper.UpdateSubmoduleConfig() | |
| 1301 self.mox.StubOutWithMock(gclient_scm.subprocess2, 'check_output', True) | |
| 1302 gclient_scm.subprocess2.check_output(['git', 'ls-files'], | |
| 1303 cwd=self.base_path, | |
| 1304 stderr=gclient_scm.subprocess2.VOID, | |
| 1305 ).AndReturn('') | |
| 1306 gclient_scm.subprocess2.check_output( | |
| 1307 ['git', 'rev-parse', '--verify', 'HEAD'], | |
| 1308 cwd=self.base_path, | |
| 1309 stderr=gclient_scm.subprocess2.VOID, | |
| 1310 ).AndReturn('') | |
| 1311 | |
| 1312 self.mox.ReplayAll() | |
| 1313 scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, | |
| 1314 relpath=self.relpath) | |
| 1315 scm.update(options, None, []) | |
| 1316 self.checkstdout('_____ Conflicting directory found in %s. Removing.\n\n' | |
| 1317 % self.base_path) | |
| 1318 | |
| 1201 | 1319 | 
| 1202 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): | 1320 class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase): | 
| 1203 def testUpdateUpdate(self): | 1321 def testUpdateUpdate(self): | 
| 1204 if not self.enabled: | 1322 if not self.enabled: | 
| 1205 return | 1323 return | 
| 1206 options = self.Options() | 1324 options = self.Options() | 
| 1207 expected_file_list = [] | 1325 expected_file_list = [] | 
| 1208 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 1326 scm = gclient_scm.CreateSCM(url=self.url, root_dir=self.root_dir, | 
| 1209 relpath=self.relpath) | 1327 relpath=self.relpath) | 
| 1210 file_list = [] | 1328 file_list = [] | 
| 1211 options.revision = 'unmanaged' | 1329 options.revision = 'unmanaged' | 
| 1212 scm.update(options, (), file_list) | 1330 scm.update(options, (), file_list) | 
| 1213 self.assertEquals(file_list, expected_file_list) | 1331 self.assertEquals(file_list, expected_file_list) | 
| 1214 self.assertEquals(scm.revinfo(options, (), None), | 1332 self.assertEquals(scm.revinfo(options, (), None), | 
| 1215 '069c602044c5388d2d15c3f875b057c852003458') | 1333 '069c602044c5388d2d15c3f875b057c852003458') | 
| 1216 self.checkstdout('________ unmanaged solution; skipping .\n') | 1334 self.checkstdout('________ unmanaged solution; skipping .\n') | 
| 1217 | 1335 | 
| 1218 | 1336 | 
| 1219 if __name__ == '__main__': | 1337 if __name__ == '__main__': | 
| 1220 if '-v' in sys.argv: | 1338 if '-v' in sys.argv: | 
| 1221 logging.basicConfig( | 1339 logging.basicConfig( | 
| 1222 level=logging.DEBUG, | 1340 level=logging.DEBUG, | 
| 1223 format='%(asctime).19s %(levelname)s %(filename)s:' | 1341 format='%(asctime).19s %(levelname)s %(filename)s:' | 
| 1224 '%(lineno)s %(message)s') | 1342 '%(lineno)s %(message)s') | 
| 1225 unittest.main() | 1343 unittest.main() | 
| 1226 | 1344 | 
| 1227 # vim: ts=2:sw=2:tw=80:et: | 1345 # vim: ts=2:sw=2:tw=80:et: | 
| OLD | NEW |