summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/fetch.py
diff options
context:
space:
mode:
authorDesone Burns <dburns@seegrid.com>2023-11-03 11:45:49 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-11-23 17:37:25 +0000
commit7aab731f1eea76d84ebe8e44e9517cbfc30fa455 (patch)
treec6e658a8860314781828ff3534fc71565f4b64c9 /bitbake/lib/bb/tests/fetch.py
parent6a87f5d53b52422f4a1e12f945495ed9951f7676 (diff)
downloadpoky-7aab731f1eea76d84ebe8e44e9517cbfc30fa455.tar.gz
bitbake: bitbake: fetch2: git: Update Git-LFS download and tests
When downloading a Git repository containing an LFS, the Git hooks are not always initialized correctly to perform the download. This change updates the Git downloader to run the "git lfs install" command in order to "smudge" the LFS files. The tests have also been updated to do checks for situations in which git lfs is not installed, as the application was required to be installed for any of the tests to run previously. The Git LFS functionality was working to some degree previously, but this change also updates the fetcher to allow LFS downloads for nobranch SRC_URIs. (Bitbake rev: 05f8529fb439db93d85a892704b6f2f0ac0c9217) Signed-off-by: Desone Burns II <dburns@seegrid.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r--bitbake/lib/bb/tests/fetch.py61
1 files changed, 35 insertions, 26 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 0e806c0ff7..c7a23407c1 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2277,7 +2277,7 @@ class GitLfsTest(FetcherTest):
2277 2277
2278 @skipIfNoGitLFS() 2278 @skipIfNoGitLFS()
2279 @skipIfNoNetwork() 2279 @skipIfNoNetwork()
2280 def test_real_git_lfs_repo_succeeds(self): 2280 def test_real_git_lfs_repo_skips(self):
2281 self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master;lfs=0") 2281 self.d.setVar('SRC_URI', "git://gitlab.com/gitlab-examples/lfs.git;protocol=https;branch=master;lfs=0")
2282 f = self.get_real_git_lfs_file() 2282 f = self.get_real_git_lfs_file()
2283 # This is the actual non-smudged placeholder file on the repo if git-lfs does not run 2283 # This is the actual non-smudged placeholder file on the repo if git-lfs does not run
@@ -2290,24 +2290,41 @@ class GitLfsTest(FetcherTest):
2290 with open(f) as fh: 2290 with open(f) as fh:
2291 self.assertEqual(lfs_file, fh.read()) 2291 self.assertEqual(lfs_file, fh.read())
2292 2292
2293 @skipIfNoGitLFS()
2293 def test_lfs_enabled(self): 2294 def test_lfs_enabled(self):
2294 import shutil 2295 import shutil
2295 2296
2296 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir 2297 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2297 self.d.setVar('SRC_URI', uri) 2298 self.d.setVar('SRC_URI', uri)
2298 2299
2299 # Careful: suppress initial attempt at downloading until 2300 # With git-lfs installed, test that we can fetch and unpack
2300 # we know whether git-lfs is installed. 2301 fetcher, ud = self.fetch()
2301 fetcher, ud = self.fetch(uri=None, download=False) 2302 shutil.rmtree(self.gitdir, ignore_errors=True)
2302 self.assertIsNotNone(ud.method._find_git_lfs) 2303 fetcher.unpack(self.d.getVar('WORKDIR'))
2303 2304
2304 # If git-lfs can be found, the unpack should be successful. Only 2305 @skipIfNoGitLFS()
2305 # attempt this with the real live copy of git-lfs installed. 2306 def test_lfs_disabled(self):
2306 if ud.method._find_git_lfs(self.d): 2307 import shutil
2307 fetcher.download() 2308
2308 shutil.rmtree(self.gitdir, ignore_errors=True) 2309 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
2309 fetcher.unpack(self.d.getVar('WORKDIR')) 2310 self.d.setVar('SRC_URI', uri)
2310 2311
2312 # Verify that the fetcher can survive even if the source
2313 # repository has Git LFS usage configured.
2314 fetcher, ud = self.fetch()
2315 fetcher.unpack(self.d.getVar('WORKDIR'))
2316
2317 def test_lfs_enabled_not_installed(self):
2318 import shutil
2319
2320 uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir
2321 self.d.setVar('SRC_URI', uri)
2322
2323 # Careful: suppress initial attempt at downloading
2324 fetcher, ud = self.fetch(uri=None, download=False)
2325
2326 # Artificially assert that git-lfs is not installed, so
2327 # we can verify a failure to unpack in it's absence.
2311 old_find_git_lfs = ud.method._find_git_lfs 2328 old_find_git_lfs = ud.method._find_git_lfs
2312 try: 2329 try:
2313 # If git-lfs cannot be found, the unpack should throw an error 2330 # If git-lfs cannot be found, the unpack should throw an error
@@ -2319,29 +2336,21 @@ class GitLfsTest(FetcherTest):
2319 finally: 2336 finally:
2320 ud.method._find_git_lfs = old_find_git_lfs 2337 ud.method._find_git_lfs = old_find_git_lfs
2321 2338
2322 def test_lfs_disabled(self): 2339 def test_lfs_disabled_not_installed(self):
2323 import shutil 2340 import shutil
2324 2341
2325 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir 2342 uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir
2326 self.d.setVar('SRC_URI', uri) 2343 self.d.setVar('SRC_URI', uri)
2327 2344
2328 # In contrast to test_lfs_enabled(), allow the implicit download 2345 # Careful: suppress initial attempt at downloading
2329 # done by self.fetch() to occur here. The point of this test case 2346 fetcher, ud = self.fetch(uri=None, download=False)
2330 # is to verify that the fetcher can survive even if the source
2331 # repository has Git LFS usage configured.
2332 fetcher, ud = self.fetch()
2333 self.assertIsNotNone(ud.method._find_git_lfs)
2334 2347
2348 # Artificially assert that git-lfs is not installed, so
2349 # we can verify a failure to unpack in it's absence.
2335 old_find_git_lfs = ud.method._find_git_lfs 2350 old_find_git_lfs = ud.method._find_git_lfs
2336 try: 2351 try:
2337 # If git-lfs can be found, the unpack should be successful. A 2352 # Even if git-lfs cannot be found, the unpack should be successful
2338 # live copy of git-lfs is not required for this case, so 2353 fetcher.download()
2339 # unconditionally forge its presence.
2340 ud.method._find_git_lfs = lambda d: True
2341 shutil.rmtree(self.gitdir, ignore_errors=True)
2342 fetcher.unpack(self.d.getVar('WORKDIR'))
2343 # If git-lfs cannot be found, the unpack should be successful
2344
2345 ud.method._find_git_lfs = lambda d: False 2354 ud.method._find_git_lfs = lambda d: False
2346 shutil.rmtree(self.gitdir, ignore_errors=True) 2355 shutil.rmtree(self.gitdir, ignore_errors=True)
2347 fetcher.unpack(self.d.getVar('WORKDIR')) 2356 fetcher.unpack(self.d.getVar('WORKDIR'))