summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/fetch.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r--bitbake/lib/bb/tests/fetch.py127
1 files changed, 127 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 0fd2c02163..510071d25d 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -852,3 +852,130 @@ class FetchCheckStatusTest(FetcherTest):
852 self.assertTrue(ret, msg="URI %s, can't check status" % (u)) 852 self.assertTrue(ret, msg="URI %s, can't check status" % (u))
853 853
854 connection_cache.close_connections() 854 connection_cache.close_connections()
855
856
857class GitMakeShallowTest(FetcherTest):
858 bitbake_dir = os.path.join(os.path.dirname(os.path.join(__file__)), '..', '..', '..')
859 make_shallow_path = os.path.join(bitbake_dir, 'bin', 'git-make-shallow')
860
861 def setUp(self):
862 FetcherTest.setUp(self)
863 self.gitdir = os.path.join(self.tempdir, 'gitshallow')
864 bb.utils.mkdirhier(self.gitdir)
865 bb.process.run('git init', cwd=self.gitdir)
866
867 def assertRefs(self, expected_refs):
868 actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines()
869 full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines()
870 self.assertEqual(sorted(full_expected), sorted(actual_refs))
871
872 def assertRevCount(self, expected_count, args=None):
873 if args is None:
874 args = ['HEAD']
875 revs = self.git(['rev-list'] + args)
876 actual_count = len(revs.splitlines())
877 self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count))
878
879 def git(self, cmd):
880 if isinstance(cmd, str):
881 cmd = 'git ' + cmd
882 else:
883 cmd = ['git'] + cmd
884 return bb.process.run(cmd, cwd=self.gitdir)[0]
885
886 def make_shallow(self, args=None):
887 if args is None:
888 args = ['HEAD']
889 return bb.process.run([self.make_shallow_path] + args, cwd=self.gitdir)
890
891 def add_empty_file(self, path, msg=None):
892 if msg is None:
893 msg = path
894 open(os.path.join(self.gitdir, path), 'w').close()
895 self.git(['add', path])
896 self.git(['commit', '-m', msg, path])
897
898 def test_make_shallow_single_branch_no_merge(self):
899 self.add_empty_file('a')
900 self.add_empty_file('b')
901 self.assertRevCount(2)
902 self.make_shallow()
903 self.assertRevCount(1)
904
905 def test_make_shallow_single_branch_one_merge(self):
906 self.add_empty_file('a')
907 self.add_empty_file('b')
908 self.git('checkout -b a_branch')
909 self.add_empty_file('c')
910 self.git('checkout master')
911 self.add_empty_file('d')
912 self.git('merge --no-ff --no-edit a_branch')
913 self.git('branch -d a_branch')
914 self.add_empty_file('e')
915 self.assertRevCount(6)
916 self.make_shallow(['HEAD~2'])
917 self.assertRevCount(5)
918
919 def test_make_shallow_at_merge(self):
920 self.add_empty_file('a')
921 self.git('checkout -b a_branch')
922 self.add_empty_file('b')
923 self.git('checkout master')
924 self.git('merge --no-ff --no-edit a_branch')
925 self.git('branch -d a_branch')
926 self.assertRevCount(3)
927 self.make_shallow()
928 self.assertRevCount(1)
929
930 def test_make_shallow_annotated_tag(self):
931 self.add_empty_file('a')
932 self.add_empty_file('b')
933 self.git('tag -a -m a_tag a_tag')
934 self.assertRevCount(2)
935 self.make_shallow(['a_tag'])
936 self.assertRevCount(1)
937
938 def test_make_shallow_multi_ref(self):
939 self.add_empty_file('a')
940 self.add_empty_file('b')
941 self.git('checkout -b a_branch')
942 self.add_empty_file('c')
943 self.git('checkout master')
944 self.add_empty_file('d')
945 self.git('checkout -b a_branch_2')
946 self.add_empty_file('a_tag')
947 self.git('tag a_tag')
948 self.git('checkout master')
949 self.git('branch -D a_branch_2')
950 self.add_empty_file('e')
951 self.assertRevCount(6, ['--all'])
952 self.make_shallow()
953 self.assertRevCount(5, ['--all'])
954
955 def test_make_shallow_multi_ref_trim(self):
956 self.add_empty_file('a')
957 self.git('checkout -b a_branch')
958 self.add_empty_file('c')
959 self.git('checkout master')
960 self.assertRevCount(1)
961 self.assertRevCount(2, ['--all'])
962 self.assertRefs(['master', 'a_branch'])
963 self.make_shallow(['-r', 'master', 'HEAD'])
964 self.assertRevCount(1, ['--all'])
965 self.assertRefs(['master'])
966
967 def test_make_shallow_noop(self):
968 self.add_empty_file('a')
969 self.assertRevCount(1)
970 self.make_shallow()
971 self.assertRevCount(1)
972
973 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
974 print("Unset BB_SKIP_NETTESTS to run network tests")
975 else:
976 def test_make_shallow_bitbake(self):
977 self.git('remote add origin https://github.com/openembedded/bitbake')
978 self.git('fetch --tags origin')
979 orig_revs = len(self.git('rev-list --all').splitlines())
980 self.make_shallow(['refs/tags/1.10.0'])
981 self.assertRevCount(orig_revs - 1746, ['--all'])