diff options
author | Philip Lorenz <philip.lorenz@bmw.de> | 2025-04-29 10:11:19 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-05-08 11:37:32 +0100 |
commit | 7642477dc8550eeff75d34bd3bbdf574e2f5687c (patch) | |
tree | 9d2f00d69555411a96af5b4848e62a0741c5bfad /bitbake/lib/bb/fetch2/git.py | |
parent | 6d0cb00c6895df6940d07dd1d5d48078e8f701f2 (diff) | |
download | poky-7642477dc8550eeff75d34bd3bbdf574e2f5687c.tar.gz |
bitbake: fetch2: Check for git-lfs existence before using it
So far, existence of `git-lfs` was only checked during unpacking. As the
binary is also used in earlier steps also check for its existence there.
Additionally, factor out the LFS existence check into a dedicated
function and call it wherever git-lfs is used for the first time.
(Bitbake rev: 5818367db9b261b7e07c347d38044e6cba8f9727)
Signed-off-by: Philip Lorenz <philip.lorenz@bmw.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 39c1839277..9e58337359 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -324,6 +324,9 @@ class Git(FetchMethod): | |||
324 | return False | 324 | return False |
325 | 325 | ||
326 | def lfs_need_update(self, ud, d): | 326 | def lfs_need_update(self, ud, d): |
327 | if not self._need_lfs(ud): | ||
328 | return False | ||
329 | |||
327 | if self.clonedir_need_update(ud, d): | 330 | if self.clonedir_need_update(ud, d): |
328 | return True | 331 | return True |
329 | 332 | ||
@@ -507,7 +510,9 @@ class Git(FetchMethod): | |||
507 | def lfs_fetch(self, ud, d, clonedir, revision, fetchall=False, progresshandler=None): | 510 | def lfs_fetch(self, ud, d, clonedir, revision, fetchall=False, progresshandler=None): |
508 | """Helper method for fetching Git LFS data""" | 511 | """Helper method for fetching Git LFS data""" |
509 | try: | 512 | try: |
510 | if self._need_lfs(ud) and self._contains_lfs(ud, d, clonedir) and self._find_git_lfs(d) and len(revision): | 513 | if self._need_lfs(ud) and self._contains_lfs(ud, d, clonedir) and len(revision): |
514 | self._ensure_git_lfs(d, ud) | ||
515 | |||
511 | # Using worktree with the revision because .lfsconfig may exists | 516 | # Using worktree with the revision because .lfsconfig may exists |
512 | worktree_add_cmd = "%s worktree add wt %s" % (ud.basecmd, revision) | 517 | worktree_add_cmd = "%s worktree add wt %s" % (ud.basecmd, revision) |
513 | runfetchcmd(worktree_add_cmd, d, log=progresshandler, workdir=clonedir) | 518 | runfetchcmd(worktree_add_cmd, d, log=progresshandler, workdir=clonedir) |
@@ -740,11 +745,11 @@ class Git(FetchMethod): | |||
740 | runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=destdir) | 745 | runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, shlex.quote(repourl)), d, workdir=destdir) |
741 | 746 | ||
742 | if self._contains_lfs(ud, d, destdir): | 747 | if self._contains_lfs(ud, d, destdir): |
743 | if need_lfs and not self._find_git_lfs(d): | 748 | if not need_lfs: |
744 | raise bb.fetch2.FetchError("Repository %s has LFS content, install git-lfs on host to download (or set lfs=0 to ignore it)" % (repourl)) | ||
745 | elif not need_lfs: | ||
746 | bb.note("Repository %s has LFS content but it is not being fetched" % (repourl)) | 749 | bb.note("Repository %s has LFS content but it is not being fetched" % (repourl)) |
747 | else: | 750 | else: |
751 | self._ensure_git_lfs(d, ud) | ||
752 | |||
748 | runfetchcmd("%s lfs install --local" % ud.basecmd, d, workdir=destdir) | 753 | runfetchcmd("%s lfs install --local" % ud.basecmd, d, workdir=destdir) |
749 | 754 | ||
750 | if not ud.nocheckout: | 755 | if not ud.nocheckout: |
@@ -807,9 +812,11 @@ class Git(FetchMethod): | |||
807 | Verifies whether the LFS objects for requested revisions have already been downloaded | 812 | Verifies whether the LFS objects for requested revisions have already been downloaded |
808 | """ | 813 | """ |
809 | # Bail out early if this repository doesn't use LFS | 814 | # Bail out early if this repository doesn't use LFS |
810 | if not self._need_lfs(ud) or not self._contains_lfs(ud, d, wd): | 815 | if not self._contains_lfs(ud, d, wd): |
811 | return True | 816 | return True |
812 | 817 | ||
818 | self._ensure_git_lfs(d, ud) | ||
819 | |||
813 | # The Git LFS specification specifies ([1]) the LFS folder layout so it should be safe to check for file | 820 | # The Git LFS specification specifies ([1]) the LFS folder layout so it should be safe to check for file |
814 | # existence. | 821 | # existence. |
815 | # [1] https://github.com/git-lfs/git-lfs/blob/main/docs/spec.md#intercepting-git | 822 | # [1] https://github.com/git-lfs/git-lfs/blob/main/docs/spec.md#intercepting-git |
@@ -859,11 +866,14 @@ class Git(FetchMethod): | |||
859 | pass | 866 | pass |
860 | return False | 867 | return False |
861 | 868 | ||
862 | def _find_git_lfs(self, d): | 869 | def _ensure_git_lfs(self, d, ud): |
863 | """ | 870 | """ |
864 | Return True if git-lfs can be found, False otherwise. | 871 | Ensures that git-lfs is available, raising a FetchError if it isn't. |
865 | """ | 872 | """ |
866 | return shutil.which("git-lfs", path=d.getVar('PATH')) is not None | 873 | if shutil.which("git-lfs", path=d.getVar('PATH')) is None: |
874 | raise bb.fetch2.FetchError( | ||
875 | "Repository %s has LFS content, install git-lfs on host to download (or set lfs=0 " | ||
876 | "to ignore it)" % self._get_repo_url(ud)) | ||
867 | 877 | ||
868 | def _get_repo_url(self, ud): | 878 | def _get_repo_url(self, ud): |
869 | """ | 879 | """ |