@@ -1739,9 +1739,15 @@ class GitMakeShallowTest(FetcherTest):
self.make_shallow(['refs/tags/1.10.0'])
self.assertRevCount(orig_revs - 1746, ['--all'])
-class GitShallowTest(FetcherTest):
+class GitShallowBaseTest():
+ """
+ Test cases for use with default shallow and fast shallow modes.
+ Test cases must succeed with `ud.shallow_fast` set to either `0` (disabled) or `1` (enabled).
+ The class GitShallowTest contains all test cases used with `ud.shallow_fast == 0` (disabled).
+ The class GitShallowFastTest contains all test cases used with `ud.shallow_fast == 1` (enabled).
+ """
+
def setUp(self):
- FetcherTest.setUp(self)
self.gitdir = os.path.join(self.tempdir, 'git')
self.srcdir = os.path.join(self.tempdir, 'gitsource')
@@ -1814,7 +1820,8 @@ class GitShallowTest(FetcherTest):
def fetch_shallow(self, uri=None, disabled=False, keepclone=False):
"""Fetch a uri, generating a shallow tarball, then unpack using it"""
fetcher, ud = self.fetch_and_unpack(uri)
- assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
+ if not ud.shallow_fast:
+ assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri)
# Confirm that the unpacked repo is unshallow
if not disabled:
@@ -1822,9 +1829,10 @@ class GitShallowTest(FetcherTest):
# fetch and unpack, from the shallow tarball
bb.utils.remove(self.gitdir, recurse=True)
- bb.process.run('chmod u+w -R "%s"' % ud.clonedir)
- bb.utils.remove(ud.clonedir, recurse=True)
- bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
+ if not ud.shallow_fast:
+ bb.process.run('chmod u+w -R "%s"' % ud.clonedir)
+ bb.utils.remove(ud.clonedir, recurse=True)
+ bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True)
# confirm that the unpacked repo is used when no git clone or git
# mirror tarball is available
@@ -1841,6 +1849,7 @@ class GitShallowTest(FetcherTest):
self.assertRevCount(2, cwd=self.srcdir)
self.d.setVar('BB_GIT_SHALLOW', '0')
+ self.d.setVar('BB_GIT_SHALLOW_FAST', '0')
self.fetch_shallow(disabled=True)
self.assertRevCount(2)
@@ -1900,26 +1909,6 @@ class GitShallowTest(FetcherTest):
self.fetch_shallow()
self.assertRevCount(2)
- def test_current_shallow_out_of_date_clone(self):
- # Create initial git repo
- self.add_empty_file('a')
- self.add_empty_file('b')
- self.add_empty_file('c')
- self.assertRevCount(3, cwd=self.srcdir)
-
- # Clone and generate mirror tarball
- fetcher, ud = self.fetch()
-
- # Ensure we have a current mirror tarball, but an out of date clone
- self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
- self.assertRevCount(2, cwd=ud.clonedir)
-
- # Fetch and unpack, from the current tarball, not the out of date clone
- bb.utils.remove(self.gitdir, recurse=True)
- fetcher, ud = self.fetch()
- fetcher.unpack(self.d.getVar('WORKDIR'))
- self.assertRevCount(1)
-
def test_shallow_single_branch_no_merge(self):
self.add_empty_file('a')
self.add_empty_file('b')
@@ -2111,16 +2100,20 @@ class GitShallowTest(FetcherTest):
self.assertRevCount(4, ['--all'])
self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
- def test_shallow_clone_preferred_over_shallow(self):
+ def test_shallow_clone_preferred_over_shallow(self, fast):
self.add_empty_file('a')
self.add_empty_file('b')
# Fetch once to generate the shallow tarball
+ if fast:
+ self.d.setVar('BB_GIT_SHALLOW_FAST', '0')
fetcher, ud = self.fetch()
assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0]))
# Fetch and unpack with both the clonedir and shallow tarball available
bb.utils.remove(self.gitdir, recurse=True)
+ if fast:
+ self.d.setVar('BB_GIT_SHALLOW_FAST', '1')
fetcher, ud = self.fetch_and_unpack()
# The unpacked tree should *not* be shallow
@@ -2240,18 +2233,6 @@ class GitShallowTest(FetcherTest):
with self.assertRaises(bb.fetch2.FetchError):
self.fetch()
- def test_shallow_fetch_missing_revs(self):
- self.add_empty_file('a')
- self.add_empty_file('b')
- fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
- self.git('tag v0.0 master', cwd=self.srcdir)
- self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
- self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
-
- with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
- self.fetch_shallow()
- self.assertIn("fatal: no commits selected for shallow requests", cm.output[0])
-
def test_shallow_fetch_missing_revs_fails(self):
self.add_empty_file('a')
self.add_empty_file('b')
@@ -2295,6 +2276,51 @@ class GitShallowTest(FetcherTest):
self.assertIn("No up to date source found", context.exception.msg)
self.assertIn("clone directory not available or not up to date", context.exception.msg)
+class GitShallowTest(GitShallowBaseTest, FetcherTest):
+ """
+ Test cases for use with default shallow mode.
+ The class contains all test cases used with disabled `ud.shallow_fast == 0` only.
+ """
+
+ def setUp(self):
+ FetcherTest.setUp(self)
+ GitShallowBaseTest.setUp(self)
+
+ def test_shallow_clone_preferred_over_shallow(self):
+ super().test_shallow_clone_preferred_over_shallow(fast=False)
+
+ def test_current_shallow_out_of_date_clone(self):
+ # Create initial git repo
+ self.add_empty_file('a')
+ self.add_empty_file('b')
+ self.add_empty_file('c')
+ self.assertRevCount(3, cwd=self.srcdir)
+
+ # Clone and generate mirror tarball
+ fetcher, ud = self.fetch()
+
+ # Ensure we have a current mirror tarball, but an out of date clone
+ self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir)
+ self.assertRevCount(2, cwd=ud.clonedir)
+
+ # Fetch and unpack, from the current tarball, not the out of date clone
+ bb.utils.remove(self.gitdir, recurse=True)
+ fetcher, ud = self.fetch()
+ fetcher.unpack(self.d.getVar('WORKDIR'))
+ self.assertRevCount(1)
+
+ def test_shallow_fetch_missing_revs(self):
+ self.add_empty_file('a')
+ self.add_empty_file('b')
+ fetcher, ud = self.fetch(self.d.getVar('SRC_URI'))
+ self.git('tag v0.0 master', cwd=self.srcdir)
+ self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
+ self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
+
+ with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm:
+ self.fetch_shallow()
+ self.assertIn("fatal: no commits selected for shallow requests", cm.output[0])
+
@skipIfNoNetwork()
def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self):
self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0')
@@ -2309,6 +2335,21 @@ class GitShallowTest(FetcherTest):
dir = os.listdir(self.unpackdir + "/git/")
self.assertIn("fstests.doap", dir)
+class GitShallowFastTest(GitShallowBaseTest, FetcherTest):
+ """
+ Test cases for use with fast shallow mode.
+ Test cases must succeed with `ud.shallow_fast` set to either `0` (disabled) or `1` (enabled).
+ The class contains all test cases used with `ud.shallow_fast == 1` (enabled) only.
+ """
+
+ def setUp(self):
+ FetcherTest.setUp(self)
+ GitShallowBaseTest.setUp(self)
+ self.d.setVar('BB_GIT_SHALLOW_FAST', '1')
+
+ def test_shallow_clone_preferred_over_shallow(self):
+ super().test_shallow_clone_preferred_over_shallow(fast=True)
+
class GitLfsTest(FetcherTest):
def skipIfNoGitLFS():
import shutil
- The class GitShallowTest contains all test cases used with `ud.shallow_fast == 0` (disabled) - The class GitShallowFastTest contains all test cases used with `ud.shallow_fast == 1` (enabled) - The base class GitShallowBaseTest contains all test cases that are used with both default shallow and fast shallow modes Signed-off-by: Stefan Koch <stefan-koch@siemens.com> --- lib/bb/tests/fetch.py | 119 ++++++++++++++++++++++++++++-------------- 1 file changed, 80 insertions(+), 39 deletions(-)