diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index b97967b487..f2cc02258e 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py | |||
@@ -141,6 +141,10 @@ class Git(FetchMethod): | |||
141 | ud.proto = 'file' | 141 | ud.proto = 'file' |
142 | else: | 142 | else: |
143 | ud.proto = "git" | 143 | ud.proto = "git" |
144 | if ud.host == "github.com" and ud.proto == "git": | ||
145 | # github stopped supporting git protocol | ||
146 | # https://github.blog/2021-09-01-improving-git-protocol-security-github/#no-more-unauthenticated-git | ||
147 | ud.proto = "https" | ||
144 | 148 | ||
145 | if not ud.proto in ('git', 'file', 'ssh', 'http', 'https', 'rsync'): | 149 | if not ud.proto in ('git', 'file', 'ssh', 'http', 'https', 'rsync'): |
146 | raise bb.fetch2.ParameterError("Invalid protocol type", ud.url) | 150 | raise bb.fetch2.ParameterError("Invalid protocol type", ud.url) |
@@ -379,6 +383,35 @@ class Git(FetchMethod): | |||
379 | if missing_rev: | 383 | if missing_rev: |
380 | raise bb.fetch2.FetchError("Unable to find revision %s even from upstream" % missing_rev) | 384 | raise bb.fetch2.FetchError("Unable to find revision %s even from upstream" % missing_rev) |
381 | 385 | ||
386 | if self._contains_lfs(ud, d, ud.clonedir) and self._need_lfs(ud): | ||
387 | # Unpack temporary working copy, use it to run 'git checkout' to force pre-fetching | ||
388 | # of all LFS blobs needed at the the srcrev. | ||
389 | # | ||
390 | # It would be nice to just do this inline here by running 'git-lfs fetch' | ||
391 | # on the bare clonedir, but that operation requires a working copy on some | ||
392 | # releases of Git LFS. | ||
393 | tmpdir = tempfile.mkdtemp(dir=d.getVar('DL_DIR')) | ||
394 | try: | ||
395 | # Do the checkout. This implicitly involves a Git LFS fetch. | ||
396 | Git.unpack(self, ud, tmpdir, d) | ||
397 | |||
398 | # Scoop up a copy of any stuff that Git LFS downloaded. Merge them into | ||
399 | # the bare clonedir. | ||
400 | # | ||
401 | # As this procedure is invoked repeatedly on incremental fetches as | ||
402 | # a recipe's SRCREV is bumped throughout its lifetime, this will | ||
403 | # result in a gradual accumulation of LFS blobs in <ud.clonedir>/lfs | ||
404 | # corresponding to all the blobs reachable from the different revs | ||
405 | # fetched across time. | ||
406 | # | ||
407 | # Only do this if the unpack resulted in a .git/lfs directory being | ||
408 | # created; this only happens if at least one blob needed to be | ||
409 | # downloaded. | ||
410 | if os.path.exists(os.path.join(tmpdir, "git", ".git", "lfs")): | ||
411 | runfetchcmd("tar -cf - lfs | tar -xf - -C %s" % ud.clonedir, d, workdir="%s/git/.git" % tmpdir) | ||
412 | finally: | ||
413 | bb.utils.remove(tmpdir, recurse=True) | ||
414 | |||
382 | def build_mirror_data(self, ud, d): | 415 | def build_mirror_data(self, ud, d): |
383 | if ud.shallow and ud.write_shallow_tarballs: | 416 | if ud.shallow and ud.write_shallow_tarballs: |
384 | if not os.path.exists(ud.fullshallow): | 417 | if not os.path.exists(ud.fullshallow): |
@@ -474,7 +507,7 @@ class Git(FetchMethod): | |||
474 | if os.path.exists(destdir): | 507 | if os.path.exists(destdir): |
475 | bb.utils.prunedir(destdir) | 508 | bb.utils.prunedir(destdir) |
476 | 509 | ||
477 | need_lfs = ud.parm.get("lfs", "1") == "1" | 510 | need_lfs = self._need_lfs(ud) |
478 | 511 | ||
479 | if not need_lfs: | 512 | if not need_lfs: |
480 | ud.basecmd = "GIT_LFS_SKIP_SMUDGE=1 " + ud.basecmd | 513 | ud.basecmd = "GIT_LFS_SKIP_SMUDGE=1 " + ud.basecmd |
@@ -563,6 +596,9 @@ class Git(FetchMethod): | |||
563 | raise bb.fetch2.FetchError("The command '%s' gave output with more then 1 line unexpectedly, output: '%s'" % (cmd, output)) | 596 | raise bb.fetch2.FetchError("The command '%s' gave output with more then 1 line unexpectedly, output: '%s'" % (cmd, output)) |
564 | return output.split()[0] != "0" | 597 | return output.split()[0] != "0" |
565 | 598 | ||
599 | def _need_lfs(self, ud): | ||
600 | return ud.parm.get("lfs", "1") == "1" | ||
601 | |||
566 | def _contains_lfs(self, ud, d, wd): | 602 | def _contains_lfs(self, ud, d, wd): |
567 | """ | 603 | """ |
568 | Check if the repository has 'lfs' (large file) content | 604 | Check if the repository has 'lfs' (large file) content |
@@ -573,8 +609,14 @@ class Git(FetchMethod): | |||
573 | else: | 609 | else: |
574 | branchname = "master" | 610 | branchname = "master" |
575 | 611 | ||
576 | cmd = "%s grep lfs origin/%s:.gitattributes | wc -l" % ( | 612 | # The bare clonedir doesn't use the remote names; it has the branch immediately. |
577 | ud.basecmd, ud.branches[ud.names[0]]) | 613 | if wd == ud.clonedir: |
614 | refname = ud.branches[ud.names[0]] | ||
615 | else: | ||
616 | refname = "origin/%s" % ud.branches[ud.names[0]] | ||
617 | |||
618 | cmd = "%s grep lfs %s:.gitattributes | wc -l" % ( | ||
619 | ud.basecmd, refname) | ||
578 | 620 | ||
579 | try: | 621 | try: |
580 | output = runfetchcmd(cmd, d, quiet=True, workdir=wd) | 622 | output = runfetchcmd(cmd, d, quiet=True, workdir=wd) |