diff options
author | Desone Burns <dburns@seegrid.com> | 2023-11-03 11:45:49 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-11-23 17:37:25 +0000 |
commit | 7aab731f1eea76d84ebe8e44e9517cbfc30fa455 (patch) | |
tree | c6e658a8860314781828ff3534fc71565f4b64c9 /bitbake/lib | |
parent | 6a87f5d53b52422f4a1e12f945495ed9951f7676 (diff) | |
download | poky-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')
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 14 | ||||
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 61 |
2 files changed, 47 insertions, 28 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 27a0d05144..5fb573a381 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -52,6 +52,11 @@ Supported SRC_URI options are: | |||
52 | For local git:// urls to use the current branch HEAD as the revision for use with | 52 | For local git:// urls to use the current branch HEAD as the revision for use with |
53 | AUTOREV. Implies nobranch. | 53 | AUTOREV. Implies nobranch. |
54 | 54 | ||
55 | - lfs | ||
56 | Enable the checkout to use LFS for large files. This will download all LFS files | ||
57 | in the download step, as the unpack step does not have network access. | ||
58 | The default is "1", set lfs=0 to skip. | ||
59 | |||
55 | """ | 60 | """ |
56 | 61 | ||
57 | # Copyright (C) 2005 Richard Purdie | 62 | # Copyright (C) 2005 Richard Purdie |
@@ -629,6 +634,8 @@ class Git(FetchMethod): | |||
629 | raise bb.fetch2.FetchError("Repository %s has LFS content, install git-lfs on host to download (or set lfs=0 to ignore it)" % (repourl)) | 634 | raise bb.fetch2.FetchError("Repository %s has LFS content, install git-lfs on host to download (or set lfs=0 to ignore it)" % (repourl)) |
630 | elif not need_lfs: | 635 | elif not need_lfs: |
631 | bb.note("Repository %s has LFS content but it is not being fetched" % (repourl)) | 636 | bb.note("Repository %s has LFS content but it is not being fetched" % (repourl)) |
637 | else: | ||
638 | runfetchcmd("%s lfs install" % ud.basecmd, d, workdir=destdir) | ||
632 | 639 | ||
633 | if not ud.nocheckout: | 640 | if not ud.nocheckout: |
634 | if subpath: | 641 | if subpath: |
@@ -688,8 +695,11 @@ class Git(FetchMethod): | |||
688 | Check if the repository has 'lfs' (large file) content | 695 | Check if the repository has 'lfs' (large file) content |
689 | """ | 696 | """ |
690 | 697 | ||
691 | # The bare clonedir doesn't use the remote names; it has the branch immediately. | 698 | if ud.nobranch: |
692 | if wd == ud.clonedir: | 699 | # If no branch is specified, use the current git commit |
700 | refname = self._build_revision(ud, d, ud.names[0]) | ||
701 | elif wd == ud.clonedir: | ||
702 | # The bare clonedir doesn't use the remote names; it has the branch immediately. | ||
693 | refname = ud.branches[ud.names[0]] | 703 | refname = ud.branches[ud.names[0]] |
694 | else: | 704 | else: |
695 | refname = "origin/%s" % ud.branches[ud.names[0]] | 705 | refname = "origin/%s" % ud.branches[ud.names[0]] |
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')) |