From: Akash Hadke <akash.hadke27@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Philip Lorenz <philip.lorenz@bmw.de>,
Richard Purdie <richard.purdie@linuxfoundation.org>
Subject: [poky][scarthgap][PATCH 19/23] bitbake: tests/fetch: Test gitsm with LFS
Date: Fri, 8 Aug 2025 14:19:27 +0530 [thread overview]
Message-ID: <20250808084931.2156763-19-akash.hadke27@gmail.com> (raw)
In-Reply-To: <20250808084931.2156763-1-akash.hadke27@gmail.com>
From: Philip Lorenz <philip.lorenz@bmw.de>
Add a test case to verify that the gitsm fetcher properly handles
repositories storing objects with LFS.
The test case verifies that LFS objects are fetched on the initial clone
but also ensures that consecutive updates extend the original clone with
any newly referenced LFS objects.
(Bitbake rev: 2a8722ddd155596862029f6ea34e1e92c77e0b7f)
Signed-off-by: Philip Lorenz <philip.lorenz@bmw.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit a7331c399252c8b365e51290c8eba3d2f6aa6fa1)
Signed-off-by: Akash Hadke <akash.hadke27@gmail.com>
---
bitbake/lib/bb/tests/fetch.py | 122 +++++++++++++++++++++++++++++++---
1 file changed, 111 insertions(+), 11 deletions(-)
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 5e76988570..6ca4745f8f 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -20,6 +20,7 @@ import tarfile
from bb.fetch2 import URI
from bb.fetch2 import FetchMethod
import bb
+import bb.utils
from bb.tests.support.httpserver import HTTPService
def skipIfNoNetwork():
@@ -27,6 +28,18 @@ def skipIfNoNetwork():
return unittest.skip("network test")
return lambda f: f
+
+@contextlib.contextmanager
+def hide_directory(directory):
+ """Hide the given directory and restore it after the context is left"""
+ temp_name = directory + ".bak"
+ os.rename(directory, temp_name)
+ try:
+ yield
+ finally:
+ os.rename(temp_name, directory)
+
+
class TestTimeout(Exception):
# Indicate to pytest that this is not a test suite
__test__ = False
@@ -2308,26 +2321,113 @@ class GitLfsTest(FetcherTest):
unpacked_lfs_file = os.path.join(self.d.getVar('WORKDIR'), 'git', "Cat_poster_1.jpg")
return unpacked_lfs_file
+ @skipIfNoGitLFS()
+ def test_gitsm_lfs(self):
+ """Test that the gitsm fetcher caches objects stored via LFS"""
+ self.git(["lfs", "install", "--local"], cwd=self.srcdir)
+
+ def fetch_and_verify(revision, filename, content):
+ self.d.setVar('SRCREV', revision)
+ fetcher, ud = self.fetch()
+
+ with hide_directory(submoduledir), hide_directory(self.srcdir):
+ workdir = self.d.getVar('WORKDIR')
+ fetcher.unpack(workdir)
+
+ with open(os.path.join(workdir, "git", filename)) as f:
+ self.assertEqual(f.read(), content)
+
+ # Create the git repository that will later be used as a submodule
+ submoduledir = self.tempdir + "/submodule"
+ bb.utils.mkdirhier(submoduledir)
+ self.git_init(submoduledir)
+ self.git(["lfs", "install", "--local"], cwd=submoduledir)
+ self.commit_file('.gitattributes', '*.mp3 filter=lfs -text', cwd=submoduledir)
+
+ submodule_commit_1 = self.commit_file("a.mp3", "submodule version 1", cwd=submoduledir)
+ _ = self.commit_file("a.mp3", "submodule version 2", cwd=submoduledir)
+
+ # Add the submodule to the repository at its current HEAD revision
+ self.git(["-c", "protocol.file.allow=always", "submodule", "add", submoduledir, "submodule"],
+ cwd=self.srcdir)
+ base_commit_1 = self.commit()
+
+ # Let the submodule point at a different revision
+ self.git(["checkout", submodule_commit_1], self.srcdir + "/submodule")
+ self.git(["add", "submodule"], cwd=self.srcdir)
+ base_commit_2 = self.commit()
+
+ # Add a LFS file to the repository
+ base_commit_3 = self.commit_file("a.mp3", "version 1")
+ # Update the added LFS file
+ base_commit_4 = self.commit_file("a.mp3", "version 2")
+
+ self.d.setVar('SRC_URI', "gitsm://%s;protocol=file;lfs=1;branch=master" % self.srcdir)
+
+ # Verify that LFS objects referenced from submodules are fetched and checked out
+ fetch_and_verify(base_commit_1, "submodule/a.mp3", "submodule version 2")
+ # Verify that the repository inside the download cache of a submodile is extended with any
+ # additional LFS objects needed when checking out a different revision.
+ fetch_and_verify(base_commit_2, "submodule/a.mp3", "submodule version 1")
+ # Verify that LFS objects referenced from the base repository are fetched and checked out
+ fetch_and_verify(base_commit_3, "a.mp3", "version 1")
+ # Verify that the cached repository is extended with any additional LFS objects required
+ # when checking out a different revision.
+ fetch_and_verify(base_commit_4, "a.mp3", "version 2")
+
+ @skipIfNoGitLFS()
+ def test_gitsm_lfs_disabled(self):
+ """Test that the gitsm fetcher does not use LFS when explicitly disabled"""
+ self.git(["lfs", "install", "--local"], cwd=self.srcdir)
+
+ def fetch_and_verify(revision, filename, content):
+ self.d.setVar('SRCREV', revision)
+ fetcher, ud = self.fetch()
+
+ with hide_directory(submoduledir), hide_directory(self.srcdir):
+ workdir = self.d.getVar('WORKDIR')
+ fetcher.unpack(workdir)
+
+ with open(os.path.join(workdir, "git", filename)) as f:
+ # Assume that LFS did not perform smudging when the expected content is
+ # missing.
+ self.assertNotEqual(f.read(), content)
+
+ # Create the git repository that will later be used as a submodule
+ submoduledir = self.tempdir + "/submodule"
+ bb.utils.mkdirhier(submoduledir)
+ self.git_init(submoduledir)
+ self.git(["lfs", "install", "--local"], cwd=submoduledir)
+ self.commit_file('.gitattributes', '*.mp3 filter=lfs -text', cwd=submoduledir)
+
+ submodule_commit_1 = self.commit_file("a.mp3", "submodule version 1", cwd=submoduledir)
+
+ # Add the submodule to the repository at its current HEAD revision
+ self.git(["-c", "protocol.file.allow=always", "submodule", "add", submoduledir, "submodule"],
+ cwd=self.srcdir)
+ base_commit_1 = self.commit()
+
+ # Add a LFS file to the repository
+ base_commit_2 = self.commit_file("a.mp3", "version 1")
+
+ self.d.setVar('SRC_URI', "gitsm://%s;protocol=file;lfs=1;branch=master;lfs=0" % self.srcdir)
+
+ # Verify that LFS objects referenced from submodules are not fetched nor checked out
+ fetch_and_verify(base_commit_1, "submodule/a.mp3", "submodule version 1")
+ # Verify that the LFS objects referenced from the base repository are not fetched nor
+ # checked out
+ fetch_and_verify(base_commit_2, "a.mp3", "version 1")
+
@skipIfNoGitLFS()
def test_fetch_lfs_on_srcrev_change(self):
"""Test if fetch downloads missing LFS objects when a different revision within an existing repository is requested"""
self.git(["lfs", "install", "--local"], cwd=self.srcdir)
- @contextlib.contextmanager
- def hide_upstream_repository():
- """Hide the upstream repository to make sure that git lfs cannot pull from it"""
- temp_name = self.srcdir + ".bak"
- os.rename(self.srcdir, temp_name)
- try:
- yield
- finally:
- os.rename(temp_name, self.srcdir)
-
def fetch_and_verify(revision, filename, content):
self.d.setVar('SRCREV', revision)
fetcher, ud = self.fetch()
- with hide_upstream_repository():
+ with hide_directory(self.srcdir):
workdir = self.d.getVar('WORKDIR')
fetcher.unpack(workdir)
--
2.25.1
next prev parent reply other threads:[~2025-08-08 8:50 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 8:49 [poky][scarthgap][PATCH 01/23] bitbake: fetch2/git: Use git shallow fetch to implement clone_shallow_local() Akash Hadke
2025-08-08 8:49 ` [poky][scarthgap][PATCH 02/23] bitbake: bitbake: tests/fetch: Update GitShallowTest for clone_shallow_local() Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 03/23] bitbake: fetch2/git: Enforce default remote name to "origin" Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 04/23] bitbake: gitsm: Add clean function Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 05/23] bitbake: git: Clean shallow mirror tarball Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 06/23] bitbake: git: Clean broken symlink Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 07/23] bitbake: lib: Remove double imports Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 08/23] bitbake: fetch2/git: Add support for fast initial shallow fetch Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 09/23] bitbake: fetch2/gitsm: Unpack even when `ud.clonedir` is not available Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 10/23] bitbake: tests/fetch: Adapt test cases for fast shallow fetches Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 11/23] bitbake: fetch2/git: Restore escape quoting for the git url when used Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 12/23] bitbake: fetch/git: always fetch lfs when creating shallow tarball Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 13/23] bitbake: tests/fetch: Move commonly used imports to top Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 14/23] bitbake: fetch2: Check for git-lfs existence before using it Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 15/23] bitbake: fetch2: Simplify git LFS detection Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 16/23] bitbake: fetch2: Use git-lfs fetch to download objects Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 17/23] bitbake: fetch2: Fix incorrect lfs parametrization for submodules Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 18/23] bitbake: fetch2: Fix LFS object checkout in submodules Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` Akash Hadke [this message]
2025-08-08 9:10 ` Patchtest results for [poky][scarthgap][PATCH 19/23] bitbake: tests/fetch: Test gitsm with LFS patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 20/23] bitbake: fetch2/git: fix shallow clone for tag containing slash Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 21/23] bitbake: fetch2: Move the `ensure_symlink()` function into the `FetchMethod` class Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 22/23] bitbake: fetch2: Ensure a valid symlink in `PREMIRRORS` case when using shallow cloning Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-08 8:49 ` [poky][scarthgap][PATCH 23/23] bitbake: fetch2/git: Add multiple revision support Akash Hadke
2025-08-08 9:10 ` Patchtest results for " patchtest
2025-08-11 8:23 ` [OE-core] " Alexander Kanavin
[not found] ` <10458.1760096658331781386@lists.openembedded.org>
2025-10-10 12:41 ` Richard Purdie
2025-08-08 9:10 ` Patchtest results for [poky][scarthgap][PATCH 01/23] bitbake: fetch2/git: Use git shallow fetch to implement clone_shallow_local() patchtest
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250808084931.2156763-19-akash.hadke27@gmail.com \
--to=akash.hadke27@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=philip.lorenz@bmw.de \
--cc=richard.purdie@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox