OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 git_common.py""" | 6 """Unit tests for git_common.py""" |
7 | 7 |
8 import binascii | 8 import binascii |
9 import collections | 9 import collections |
10 import os | 10 import os |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 def testMkTree(self): | 324 def testMkTree(self): |
325 tree = {} | 325 tree = {} |
326 for i in 1, 2, 3: | 326 for i in 1, 2, 3: |
327 name = 'file%d' % i | 327 name = 'file%d' % i |
328 tree[name] = ('100644', 'blob', self._intern_data(name)) | 328 tree[name] = ('100644', 'blob', self._intern_data(name)) |
329 tree_hash = self.repo.run(self.gc.mktree, tree) | 329 tree_hash = self.repo.run(self.gc.mktree, tree) |
330 self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash) | 330 self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash) |
331 | 331 |
332 def testConfig(self): | 332 def testConfig(self): |
333 self.repo.git('config', '--add', 'happy.derpies', 'food') | 333 self.repo.git('config', '--add', 'happy.derpies', 'food') |
334 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), | 334 self.assertEquals(self.repo.run(self.gc.get_config_list, 'happy.derpies'), |
335 ['food']) | 335 ['food']) |
336 self.assertEquals(self.repo.run(self.gc.config_list, 'sad.derpies'), []) | 336 self.assertEquals(self.repo.run(self.gc.get_config_list, 'sad.derpies'), []) |
337 | 337 |
338 self.repo.git('config', '--add', 'happy.derpies', 'cat') | 338 self.repo.git('config', '--add', 'happy.derpies', 'cat') |
339 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), | 339 self.assertEquals(self.repo.run(self.gc.get_config_list, 'happy.derpies'), |
340 ['food', 'cat']) | 340 ['food', 'cat']) |
341 | 341 |
342 self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) | 342 self.assertEquals('cat', self.repo.run(self.gc.get_config, 'dude.bob', |
| 343 'cat')) |
343 | 344 |
344 self.repo.run(self.gc.set_config, 'dude.bob', 'dog') | 345 self.repo.run(self.gc.set_config, 'dude.bob', 'dog') |
345 | 346 |
346 self.assertEquals('dog', self.repo.run(self.gc.config, 'dude.bob', 'cat')) | 347 self.assertEquals('dog', self.repo.run(self.gc.get_config, 'dude.bob', |
| 348 'cat')) |
347 | 349 |
348 self.repo.run(self.gc.del_config, 'dude.bob') | 350 self.repo.run(self.gc.del_config, 'dude.bob') |
349 | 351 |
350 # This should work without raising an exception | 352 # This should work without raising an exception |
351 self.repo.run(self.gc.del_config, 'dude.bob') | 353 self.repo.run(self.gc.del_config, 'dude.bob') |
352 | 354 |
353 self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) | 355 self.assertEquals('cat', self.repo.run(self.gc.get_config, 'dude.bob', |
| 356 'cat')) |
354 | 357 |
355 self.assertEquals('origin/master', self.repo.run(self.gc.root)) | 358 self.assertEquals('origin/master', self.repo.run(self.gc.root)) |
356 | 359 |
357 self.repo.git('config', 'depot-tools.upstream', 'catfood') | 360 self.repo.git('config', 'depot-tools.upstream', 'catfood') |
358 | 361 |
359 self.assertEquals('catfood', self.repo.run(self.gc.root)) | 362 self.assertEquals('catfood', self.repo.run(self.gc.root)) |
360 | 363 |
361 def testUpstream(self): | 364 def testUpstream(self): |
362 self.repo.git('commit', '--allow-empty', '-am', 'foooooo') | 365 self.repo.git('commit', '--allow-empty', '-am', 'foooooo') |
363 self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None) | 366 self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 self.repo['B'], | 421 self.repo['B'], |
419 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') | 422 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
420 ) | 423 ) |
421 | 424 |
422 self.assertEqual( | 425 self.assertEqual( |
423 self.repo['J'], | 426 self.repo['J'], |
424 self.repo.run(self.gc.get_or_create_merge_base, 'branch_L', 'branch_K') | 427 self.repo.run(self.gc.get_or_create_merge_base, 'branch_L', 'branch_K') |
425 ) | 428 ) |
426 | 429 |
427 self.assertEqual( | 430 self.assertEqual( |
428 self.repo['B'], self.repo.run(self.gc.config, 'branch.branch_K.base') | 431 self.repo['B'], self.repo.run(self.gc.get_config, 'branch.branch_K.base') |
429 ) | 432 ) |
430 self.assertEqual( | 433 self.assertEqual( |
431 'branch_G', self.repo.run(self.gc.config, 'branch.branch_K.base-upstream') | 434 'branch_G', self.repo.run(self.gc.get_config, |
| 435 'branch.branch_K.base-upstream') |
432 ) | 436 ) |
433 | 437 |
434 # deadbeef is a bad hash, so this will result in repo['B'] | 438 # deadbeef is a bad hash, so this will result in repo['B'] |
435 self.repo.run(self.gc.manual_merge_base, 'branch_K', 'deadbeef', 'branch_G') | 439 self.repo.run(self.gc.manual_merge_base, 'branch_K', 'deadbeef', 'branch_G') |
436 | 440 |
437 self.assertEqual( | 441 self.assertEqual( |
438 self.repo['B'], | 442 self.repo['B'], |
439 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') | 443 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
440 ) | 444 ) |
441 | 445 |
442 # but if we pick a real ancestor, then it'll work | 446 # but if we pick a real ancestor, then it'll work |
443 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['I'], | 447 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['I'], |
444 'branch_G') | 448 'branch_G') |
445 | 449 |
446 self.assertEqual( | 450 self.assertEqual( |
447 self.repo['I'], | 451 self.repo['I'], |
448 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') | 452 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
449 ) | 453 ) |
450 | 454 |
451 self.assertEqual({'branch_K': self.repo['I'], 'branch_L': self.repo['J']}, | 455 self.assertEqual({'branch_K': self.repo['I'], 'branch_L': self.repo['J']}, |
452 self.repo.run(self.gc.branch_config_map, 'base')) | 456 self.repo.run(self.gc.branch_config_map, 'base')) |
453 | 457 |
454 self.repo.run(self.gc.remove_merge_base, 'branch_K') | 458 self.repo.run(self.gc.remove_merge_base, 'branch_K') |
455 self.repo.run(self.gc.remove_merge_base, 'branch_L') | 459 self.repo.run(self.gc.remove_merge_base, 'branch_L') |
456 | 460 |
457 self.assertEqual(None, | 461 self.assertEqual(None, self.repo.run(self.gc.get_config, |
458 self.repo.run(self.gc.config, 'branch.branch_K.base')) | 462 'branch.branch_K.base')) |
459 | 463 |
460 self.assertEqual({}, self.repo.run(self.gc.branch_config_map, 'base')) | 464 self.assertEqual({}, self.repo.run(self.gc.branch_config_map, 'base')) |
461 | 465 |
462 # if it's too old, then it caps at merge-base | 466 # if it's too old, then it caps at merge-base |
463 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['A'], | 467 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['A'], |
464 'branch_G') | 468 'branch_G') |
465 | 469 |
466 self.assertEqual( | 470 self.assertEqual( |
467 self.repo['B'], | 471 self.repo['B'], |
468 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') | 472 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 self.repo.git('rebase', '--continue') | 574 self.repo.git('rebase', '--continue') |
571 | 575 |
572 self.assertSchema(""" | 576 self.assertSchema(""" |
573 A B C D E F G H I J K L | 577 A B C D E F G H I J K L |
574 | 578 |
575 X Y Z | 579 X Y Z |
576 | 580 |
577 CAT DOG | 581 CAT DOG |
578 """) | 582 """) |
579 | 583 |
| 584 def testStatus(self): |
| 585 def inner(): |
| 586 dictified_status = lambda: { |
| 587 k: dict(v._asdict()) # pylint: disable=W0212 |
| 588 for k, v in self.repo.run(self.gc.status).iteritems() |
| 589 } |
| 590 self.repo.git('mv', 'file', 'cat') |
| 591 with open('COOL', 'w') as f: |
| 592 f.write('Super cool file!') |
| 593 self.assertDictEqual( |
| 594 dictified_status(), |
| 595 {'cat': {'lstat': 'R', 'rstat': ' ', 'src': 'file'}, |
| 596 'COOL': {'lstat': '?', 'rstat': '?', 'src': 'COOL'}} |
| 597 ) |
| 598 |
| 599 self.repo.run(inner) |
| 600 |
580 | 601 |
581 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase): | 602 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase): |
582 @classmethod | 603 @classmethod |
583 def setUpClass(cls): | 604 def setUpClass(cls): |
584 super(GitFreezeThaw, cls).setUpClass() | 605 super(GitFreezeThaw, cls).setUpClass() |
585 import git_common | 606 import git_common |
586 cls.gc = git_common | 607 cls.gc = git_common |
587 cls.gc.TEST_MODE = True | 608 cls.gc.TEST_MODE = True |
588 | 609 |
589 REPO_SCHEMA = """ | 610 REPO_SCHEMA = """ |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '') | 669 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '') |
649 | 670 |
650 # Thaw it out! | 671 # Thaw it out! |
651 self.assertIsNone(self.gc.thaw()) | 672 self.assertIsNone(self.gc.thaw()) |
652 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything | 673 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything |
653 | 674 |
654 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) | 675 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) |
655 | 676 |
656 self.repo.run(inner) | 677 self.repo.run(inner) |
657 | 678 |
| 679 def testTooBig(self): |
| 680 def inner(): |
| 681 self.repo.git('config', 'depot-tools.freeze-size-limit', '1') |
| 682 with open('bigfile', 'w') as f: |
| 683 chunk = 'NERDFACE' * 1024 |
| 684 for _ in xrange(128 * 2 + 1): # Just over 2 mb |
| 685 f.write(chunk) |
| 686 _, err = self.repo.capture_stdio(self.gc.freeze) |
| 687 self.assertIn('too much untracked+unignored', err) |
| 688 |
| 689 self.repo.run(inner) |
| 690 |
| 691 def testMerge(self): |
| 692 def inner(): |
| 693 self.repo.git('checkout', '-b', 'bad_merge_branch') |
| 694 with open('bad_merge', 'w') as f: |
| 695 f.write('bad_merge_left') |
| 696 self.repo.git('add', 'bad_merge') |
| 697 self.repo.git('commit', '-m', 'bad_merge') |
| 698 |
| 699 self.repo.git('checkout', 'branch_D') |
| 700 with open('bad_merge', 'w') as f: |
| 701 f.write('bad_merge_right') |
| 702 self.repo.git('add', 'bad_merge') |
| 703 self.repo.git('commit', '-m', 'bad_merge_d') |
| 704 |
| 705 self.repo.git('merge', 'bad_merge_branch') |
| 706 |
| 707 _, err = self.repo.capture_stdio(self.gc.freeze) |
| 708 self.assertIn('Cannot freeze unmerged changes', err) |
| 709 |
| 710 self.repo.run(inner) |
| 711 |
658 | 712 |
659 if __name__ == '__main__': | 713 if __name__ == '__main__': |
660 sys.exit(coverage_utils.covered_main( | 714 sys.exit(coverage_utils.covered_main( |
661 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') | 715 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py') |
662 )) | 716 )) |
OLD | NEW |