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

Side by Side Diff: tests/git_common_test.py

Issue 2052113002: Make git-freeze bail out if the user has too much untracked data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 4 years, 6 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
« git_common.py ('K') | « man/src/git-freeze.txt ('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 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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 def testMkTree(self): 408 def testMkTree(self):
409 tree = {} 409 tree = {}
410 for i in 1, 2, 3: 410 for i in 1, 2, 3:
411 name = 'file%d' % i 411 name = 'file%d' % i
412 tree[name] = ('100644', 'blob', self._intern_data(name)) 412 tree[name] = ('100644', 'blob', self._intern_data(name))
413 tree_hash = self.repo.run(self.gc.mktree, tree) 413 tree_hash = self.repo.run(self.gc.mktree, tree)
414 self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash) 414 self.assertEquals('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash)
415 415
416 def testConfig(self): 416 def testConfig(self):
417 self.repo.git('config', '--add', 'happy.derpies', 'food') 417 self.repo.git('config', '--add', 'happy.derpies', 'food')
418 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), 418 self.assertEquals(self.repo.run(self.gc.get_config_list, 'happy.derpies'),
419 ['food']) 419 ['food'])
420 self.assertEquals(self.repo.run(self.gc.config_list, 'sad.derpies'), []) 420 self.assertEquals(self.repo.run(self.gc.get_config_list, 'sad.derpies'), [])
421 421
422 self.repo.git('config', '--add', 'happy.derpies', 'cat') 422 self.repo.git('config', '--add', 'happy.derpies', 'cat')
423 self.assertEquals(self.repo.run(self.gc.config_list, 'happy.derpies'), 423 self.assertEquals(self.repo.run(self.gc.get_config_list, 'happy.derpies'),
424 ['food', 'cat']) 424 ['food', 'cat'])
425 425
426 self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) 426 self.assertEquals('cat', self.repo.run(self.gc.get_config, 'dude.bob',
427 'cat'))
427 428
428 self.repo.run(self.gc.set_config, 'dude.bob', 'dog') 429 self.repo.run(self.gc.set_config, 'dude.bob', 'dog')
429 430
430 self.assertEquals('dog', self.repo.run(self.gc.config, 'dude.bob', 'cat')) 431 self.assertEquals('dog', self.repo.run(self.gc.get_config, 'dude.bob',
432 'cat'))
431 433
432 self.repo.run(self.gc.del_config, 'dude.bob') 434 self.repo.run(self.gc.del_config, 'dude.bob')
433 435
434 # This should work without raising an exception 436 # This should work without raising an exception
435 self.repo.run(self.gc.del_config, 'dude.bob') 437 self.repo.run(self.gc.del_config, 'dude.bob')
436 438
437 self.assertEquals('cat', self.repo.run(self.gc.config, 'dude.bob', 'cat')) 439 self.assertEquals('cat', self.repo.run(self.gc.get_config, 'dude.bob',
440 'cat'))
438 441
439 self.assertEquals('origin/master', self.repo.run(self.gc.root)) 442 self.assertEquals('origin/master', self.repo.run(self.gc.root))
440 443
441 self.repo.git('config', 'depot-tools.upstream', 'catfood') 444 self.repo.git('config', 'depot-tools.upstream', 'catfood')
442 445
443 self.assertEquals('catfood', self.repo.run(self.gc.root)) 446 self.assertEquals('catfood', self.repo.run(self.gc.root))
444 447
445 def testUpstream(self): 448 def testUpstream(self):
446 self.repo.git('commit', '--allow-empty', '-am', 'foooooo') 449 self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
447 self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None) 450 self.assertEquals(self.repo.run(self.gc.upstream, 'bobly'), None)
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 self.repo['B'], 555 self.repo['B'],
553 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') 556 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G')
554 ) 557 )
555 558
556 self.assertEqual( 559 self.assertEqual(
557 self.repo['J'], 560 self.repo['J'],
558 self.repo.run(self.gc.get_or_create_merge_base, 'branch_L', 'branch_K') 561 self.repo.run(self.gc.get_or_create_merge_base, 'branch_L', 'branch_K')
559 ) 562 )
560 563
561 self.assertEqual( 564 self.assertEqual(
562 self.repo['B'], self.repo.run(self.gc.config, 'branch.branch_K.base') 565 self.repo['B'], self.repo.run(self.gc.get_config, 'branch.branch_K.base')
563 ) 566 )
564 self.assertEqual( 567 self.assertEqual(
565 'branch_G', self.repo.run(self.gc.config, 'branch.branch_K.base-upstream') 568 'branch_G', self.repo.run(self.gc.get_config,
569 'branch.branch_K.base-upstream')
566 ) 570 )
567 571
568 # deadbeef is a bad hash, so this will result in repo['B'] 572 # deadbeef is a bad hash, so this will result in repo['B']
569 self.repo.run(self.gc.manual_merge_base, 'branch_K', 'deadbeef', 'branch_G') 573 self.repo.run(self.gc.manual_merge_base, 'branch_K', 'deadbeef', 'branch_G')
570 574
571 self.assertEqual( 575 self.assertEqual(
572 self.repo['B'], 576 self.repo['B'],
573 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') 577 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G')
574 ) 578 )
575 579
576 # but if we pick a real ancestor, then it'll work 580 # but if we pick a real ancestor, then it'll work
577 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['I'], 581 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['I'],
578 'branch_G') 582 'branch_G')
579 583
580 self.assertEqual( 584 self.assertEqual(
581 self.repo['I'], 585 self.repo['I'],
582 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') 586 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G')
583 ) 587 )
584 588
585 self.assertEqual({'branch_K': self.repo['I'], 'branch_L': self.repo['J']}, 589 self.assertEqual({'branch_K': self.repo['I'], 'branch_L': self.repo['J']},
586 self.repo.run(self.gc.branch_config_map, 'base')) 590 self.repo.run(self.gc.branch_config_map, 'base'))
587 591
588 self.repo.run(self.gc.remove_merge_base, 'branch_K') 592 self.repo.run(self.gc.remove_merge_base, 'branch_K')
589 self.repo.run(self.gc.remove_merge_base, 'branch_L') 593 self.repo.run(self.gc.remove_merge_base, 'branch_L')
590 594
591 self.assertEqual(None, 595 self.assertEqual(None, self.repo.run(self.gc.get_config,
592 self.repo.run(self.gc.config, 'branch.branch_K.base')) 596 'branch.branch_K.base'))
593 597
594 self.assertEqual({}, self.repo.run(self.gc.branch_config_map, 'base')) 598 self.assertEqual({}, self.repo.run(self.gc.branch_config_map, 'base'))
595 599
596 # if it's too old, then it caps at merge-base 600 # if it's too old, then it caps at merge-base
597 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['A'], 601 self.repo.run(self.gc.manual_merge_base, 'branch_K', self.repo['A'],
598 'branch_G') 602 'branch_G')
599 603
600 self.assertEqual( 604 self.assertEqual(
601 self.repo['B'], 605 self.repo['B'],
602 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G') 606 self.repo.run(self.gc.get_or_create_merge_base, 'branch_K', 'branch_G')
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 self.repo.git('rebase', '--continue') 724 self.repo.git('rebase', '--continue')
721 725
722 self.assertSchema(""" 726 self.assertSchema("""
723 A B C D E F G H I J K L 727 A B C D E F G H I J K L
724 728
725 X Y Z 729 X Y Z
726 730
727 CAT DOG 731 CAT DOG
728 """) 732 """)
729 733
734 def testStatus(self):
735 def inner():
736 dictified_status = lambda: {
737 k: dict(v._asdict()) # pylint: disable=W0212
738 for k, v in self.repo.run(self.gc.status).iteritems()
739 }
740 self.repo.git('mv', 'file', 'cat')
741 with open('COOL', 'w') as f:
742 f.write('Super cool file!')
743 self.assertDictEqual(
744 dictified_status(),
745 {'cat': {'lstat': 'R', 'rstat': ' ', 'src': 'file'},
746 'COOL': {'lstat': '?', 'rstat': '?', 'src': 'COOL'}}
747 )
748
749 self.repo.run(inner)
750
730 751
731 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase): 752 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase):
732 @classmethod 753 @classmethod
733 def setUpClass(cls): 754 def setUpClass(cls):
734 super(GitFreezeThaw, cls).setUpClass() 755 super(GitFreezeThaw, cls).setUpClass()
735 import git_common 756 import git_common
736 cls.gc = git_common 757 cls.gc = git_common
737 cls.gc.TEST_MODE = True 758 cls.gc.TEST_MODE = True
738 759
739 REPO_SCHEMA = """ 760 REPO_SCHEMA = """
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '') 819 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '')
799 820
800 # Thaw it out! 821 # Thaw it out!
801 self.assertIsNone(self.gc.thaw()) 822 self.assertIsNone(self.gc.thaw())
802 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything 823 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything
803 824
804 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) 825 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1)
805 826
806 self.repo.run(inner) 827 self.repo.run(inner)
807 828
829 def testTooBig(self):
830 def inner():
831 self.repo.git('config', 'depot-tools.freeze-size-limit', '1')
832 with open('bigfile', 'w') as f:
833 chunk = 'NERDFACE' * 1024
834 for _ in xrange(128 * 2 + 1): # Just over 2 mb
835 f.write(chunk)
836 _, err = self.repo.capture_stdio(self.gc.freeze)
837 self.assertIn('too much untracked+unignored', err)
838
839 self.repo.run(inner)
840
841 def testMerge(self):
842 def inner():
843 self.repo.git('checkout', '-b', 'bad_merge_branch')
844 with open('bad_merge', 'w') as f:
845 f.write('bad_merge_left')
846 self.repo.git('add', 'bad_merge')
847 self.repo.git('commit', '-m', 'bad_merge')
848
849 self.repo.git('checkout', 'branch_D')
850 with open('bad_merge', 'w') as f:
851 f.write('bad_merge_right')
852 self.repo.git('add', 'bad_merge')
853 self.repo.git('commit', '-m', 'bad_merge_d')
854
855 self.repo.git('merge', 'bad_merge_branch')
856
857 _, err = self.repo.capture_stdio(self.gc.freeze)
858 self.assertIn('Cannot freeze unmerged changes', err)
859
860 self.repo.run(inner)
861
808 862
809 class GitMakeWorkdir(git_test_utils.GitRepoReadOnlyTestBase, GitCommonTestBase): 863 class GitMakeWorkdir(git_test_utils.GitRepoReadOnlyTestBase, GitCommonTestBase):
810 def setUp(self): 864 def setUp(self):
811 self._tempdir = tempfile.mkdtemp() 865 self._tempdir = tempfile.mkdtemp()
812 866
813 def tearDown(self): 867 def tearDown(self):
814 shutil.rmtree(self._tempdir) 868 shutil.rmtree(self._tempdir)
815 869
816 REPO_SCHEMA = """ 870 REPO_SCHEMA = """
817 A 871 A
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 self.repo.show_commit('A', format_string='%cn %ci')) 912 self.repo.show_commit('A', format_string='%cn %ci'))
859 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000', 913 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000',
860 self.repo.show_commit('B', format_string='%an %ai')) 914 self.repo.show_commit('B', format_string='%an %ai'))
861 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000', 915 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000',
862 self.repo.show_commit('B', format_string='%cn %ci')) 916 self.repo.show_commit('B', format_string='%cn %ci'))
863 917
864 918
865 if __name__ == '__main__': 919 if __name__ == '__main__':
866 sys.exit(coverage_utils.covered_main( 920 sys.exit(coverage_utils.covered_main(
867 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'))) 921 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py')))
OLDNEW
« git_common.py ('K') | « man/src/git-freeze.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698