From d8b0adfaac9118777d099f76c428e088da519ff0 Mon Sep 17 00:00:00 2001 From: "Koch, Stefan" Date: Tue, 27 May 2025 11:59:03 +0200 Subject: [PATCH] bitbake: tests/fetch: Add test case to check shallow cloning using `PREMIRRORS` (Bitbake rev: 6e1434d93d489aa4bab07777a7a9dc58ba0ca5a7) Signed-off-by: Stefan Koch Signed-off-by: Richard Purdie --- bitbake/lib/bb/tests/fetch.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 3f42332588..077472b8b3 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py @@ -2237,6 +2237,33 @@ class GitShallowTest(FetcherTest): self.fetch_shallow() self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0]) + @skipIfNoNetwork() + def test_git_shallow_fetch_premirrors(self): + url = "git://git.openembedded.org/bitbake;branch=master;protocol=https" + + # Create a separate premirror directory within tempdir + premirror = os.path.join(self.tempdir, "premirror") + os.mkdir(premirror) + + # Fetch a non-shallow clone into the premirror subdir + self.d.setVar('BB_GIT_SHALLOW', '0') + self.d.setVar("DL_DIR", premirror) + fetcher, ud = self.fetch(url) + + # Fetch a shallow clone from the premirror subdir with unpacking + # using the original recipe URL and the premirror mapping + self.d.setVar('BB_GIT_SHALLOW', '1') + self.d.setVar("DL_DIR", self.dldir) + self.d.setVar('BB_FETCH_PREMIRRORONLY', '1') + self.d.setVar('BB_NO_NETWORK', '1') + self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0') + self.d.setVar("PREMIRRORS", "git://.*/.* git://{0};protocol=file".format(premirror + "/git2/" + ud.host + ud.path.replace("/", "."))) + fetcher = self.fetch_and_unpack(url) + + # Verify that the unpacked sources are shallow clones + self.assertRevCount(1) + assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')) + @skipIfNoNetwork() def test_bitbake(self): self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir)