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

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: Final comment 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
« no previous file with comments | « 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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 self.repo.git('rebase', '--continue') 724 self.repo.git('rebase', '--continue')
725 725
726 self.assertSchema(""" 726 self.assertSchema("""
727 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
728 728
729 X Y Z 729 X Y Z
730 730
731 CAT DOG 731 CAT DOG
732 """) 732 """)
733 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)
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
734 751
735 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase): 752 class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase):
736 @classmethod 753 @classmethod
737 def setUpClass(cls): 754 def setUpClass(cls):
738 super(GitFreezeThaw, cls).setUpClass() 755 super(GitFreezeThaw, cls).setUpClass()
739 import git_common 756 import git_common
740 cls.gc = git_common 757 cls.gc = git_common
741 cls.gc.TEST_MODE = True 758 cls.gc.TEST_MODE = True
742 759
743 REPO_SCHEMA = """ 760 REPO_SCHEMA = """
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '') 819 self.assertEquals(self.repo.git('status', '--porcelain').stdout, '')
803 820
804 # Thaw it out! 821 # Thaw it out!
805 self.assertIsNone(self.gc.thaw()) 822 self.assertIsNone(self.gc.thaw())
806 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything 823 self.assertIsNotNone(self.gc.thaw()) # One thaw should thaw everything
807 824
808 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1) 825 self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1)
809 826
810 self.repo.run(inner) 827 self.repo.run(inner)
811 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 testTooBigMultipleFiles(self):
842 def inner():
843 self.repo.git('config', 'depot-tools.freeze-size-limit', '1')
844 for i in xrange(3):
845 with open('file%d' % i, 'w') as f:
846 chunk = 'NERDFACE' * 1024
847 for _ in xrange(50): # About 400k
848 f.write(chunk)
849 _, err = self.repo.capture_stdio(self.gc.freeze)
850 self.assertIn('too much untracked+unignored', err)
851
852 self.repo.run(inner)
853
854 def testMerge(self):
855 def inner():
856 self.repo.git('checkout', '-b', 'bad_merge_branch')
857 with open('bad_merge', 'w') as f:
858 f.write('bad_merge_left')
859 self.repo.git('add', 'bad_merge')
860 self.repo.git('commit', '-m', 'bad_merge')
861
862 self.repo.git('checkout', 'branch_D')
863 with open('bad_merge', 'w') as f:
864 f.write('bad_merge_right')
865 self.repo.git('add', 'bad_merge')
866 self.repo.git('commit', '-m', 'bad_merge_d')
867
868 self.repo.git('merge', 'bad_merge_branch')
869
870 _, err = self.repo.capture_stdio(self.gc.freeze)
871 self.assertIn('Cannot freeze unmerged changes', err)
872
873 self.repo.run(inner)
874
812 875
813 class GitMakeWorkdir(git_test_utils.GitRepoReadOnlyTestBase, GitCommonTestBase): 876 class GitMakeWorkdir(git_test_utils.GitRepoReadOnlyTestBase, GitCommonTestBase):
814 def setUp(self): 877 def setUp(self):
815 self._tempdir = tempfile.mkdtemp() 878 self._tempdir = tempfile.mkdtemp()
816 879
817 def tearDown(self): 880 def tearDown(self):
818 shutil.rmtree(self._tempdir) 881 shutil.rmtree(self._tempdir)
819 882
820 REPO_SCHEMA = """ 883 REPO_SCHEMA = """
821 A 884 A
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 self.repo.show_commit('A', format_string='%cn %ci')) 925 self.repo.show_commit('A', format_string='%cn %ci'))
863 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000', 926 self.assertEquals('Author McAuthorly 1970-01-03 00:00:00 +0000',
864 self.repo.show_commit('B', format_string='%an %ai')) 927 self.repo.show_commit('B', format_string='%an %ai'))
865 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000', 928 self.assertEquals('Charles Committish 1970-01-04 00:00:00 +0000',
866 self.repo.show_commit('B', format_string='%cn %ci')) 929 self.repo.show_commit('B', format_string='%cn %ci'))
867 930
868 931
869 if __name__ == '__main__': 932 if __name__ == '__main__':
870 sys.exit(coverage_utils.covered_main( 933 sys.exit(coverage_utils.covered_main(
871 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py'))) 934 os.path.join(DEPOT_TOOLS_ROOT, 'git_common.py')))
OLDNEW
« no previous file with comments | « man/src/git-freeze.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698