fetch2: Raise on git lfs fetch failures
PATCH 1/1 fetch2: Raise on git lfs fetch failures
LFS fetching can fail and ignoring this will lead to an incomplete download cache (which in turn will lead to errors when smudging the LFS files during unpack). Avoid this by removing the exception silencing code.
In addition, this change disables smudging during worktree creation so LFS related errors are now raised during the execution of git lfs fetch rather than during worktree creation.
LFS fetching is only performed on repositories which are considered LFS enabled and can be disabled by parametrizing the repository URL with lfs=0.
Signed-off-by Philip Lorenz <[email protected]>
--- lib/bb/fetch2/git.py | 28 ++++++++++++++-------------- lib/bb/tests/fetch.py | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-)
lib/bb/fetch2/git.py +14 -14
@@ -498,21 +498,21 @@ class Git(FetchMethod): def lfs_fetch(self, ud, d, clonedir, revision, fetchall=False, progresshandler=None): """Helper method for fetching Git LFS data""" - try: - if self._need_lfs(ud) and self._contains_lfs(ud, d, clonedir) and len(revision): - self._ensure_git_lfs(d, ud) + if self._need_lfs(ud) and self._contains_lfs(ud, d, clonedir) and len(revision): + self._ensure_git_lfs(d, ud) + + # Using worktree with the revision because .lfsconfig may exists + worktree_add_cmd = ud.basecmd + ['worktree', 'add', 'wt', revision] + # Disable LFS smudging on worktree creation to make it easier + # to understand which operation actually failed. + runfetchcmd(worktree_add_cmd, d, log=progresshandler, workdir=clonedir, extraenv={'GIT_LFS_SKIP_SMUDGE':'1'}) + lfs_fetch_cmd = ud.basecmd + ['lfs', 'fetch'] + if fetchall: + lfs_fetch_cmd.append('--all') + runfetchcmd(lfs_fetch_cmd, d, log=progresshandler, workdir=(clonedir + "/wt")) + worktree_rem_cmd = ud.basecmd + ['worktree', 'remove', '-f', 'wt'] + runfetchcmd(worktree_rem_cmd, d, log=progresshandler, workdir=clonedir) - # Using worktree with the revision because .lfsconfig may exists - worktree_add_cmd = ud.basecmd + ['worktree', 'add', 'wt', revision] - runfetchcmd(worktree_add_cmd, d, log=progresshandler, workdir=clonedir) - lfs_fetch_cmd = ud.basecmd + ['lfs', 'fetch'] - if fetchall: - lfs_fetch_cmd.append('--all') - runfetchcmd(lfs_fetch_cmd, d, log=progresshandler, workdir=(clonedir + "/wt")) - worktree_rem_cmd = ud.basecmd + ['worktree', 'remove', '-f', 'wt'] - runfetchcmd(worktree_rem_cmd, d, log=progresshandler, workdir=clonedir) - except: - logger.warning("Fetching LFS did not succeed.") @contextmanager def create_atomic(self, filename):
lib/bb/tests/fetch.py +15 -0
@@ -2807,6 +2807,21 @@ class GitLfsTest(FetcherTest): shutil.rmtree(self.gitdir, ignore_errors=True) fetcher.unpack(self.d.getVar('WORKDIR')) + @skipIfNoGitLFS() + def test_lfs_fetch_failure_raises(self): + self.commit_file("a.mp3", "version 1") + + uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir + self.d.setVar('SRC_URI', uri) + + # Simulate a fetch failure by removing the .git/lfs/objects directory + # from the source repository + shutil.rmtree(os.path.join(self.srcdir, ".git", "lfs", "objects")) + + # Test than exception is raised when LFS objects could not be fetched + with self.assertRaises(bb.fetch2.FetchError): + self.fetch() + class GitURLWithSpacesTest(FetcherTest): test_git_urls = { "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : {
Signature · 1 line
2.55.0