[bitbake-devel] [PATCH] fetch2/git.py: try to handle local clone failures by pruning branches

Mikko Rapeli mikko.rapeli at bmw.de
Wed Aug 2 09:47:44 UTC 2017


Switching bitbake build environment from Ubuntu 14.04 to 16.04 brought
up this incompatibility between download cache data generated with
git 1.9.x.

In git 1.9.x from Ubuntu 14.04 local cloning succeeds even if source tree
has non-existing remote branches, which have been deleted in upstream git
tree.

In git 2.7.x from Ubuntu 16.04 cloning fails with an error:

downloads/git2$ git clone sourceware.org.git.glibc.git/ /tmp/
Cloning into '/tmp'...
done.
fatal: cannot process 'refs/remotes/origin/hjl/memcpy' and 'refs/remotes/origin/hjl/memcpy/dpdk/master' at the same time
fatal: The remote end hung up unexpectedly

Work around this by pruning non-existing remote branches from the git
tree in download cache if cloning failed, and then try the local clone
again.

Another workaround is to do those steps manually for every download cache,
but that does not scale in large distributed build environments.

Signed-off-by: Mikko Rapeli <mikko.rapeli at bmw.de>
---
 lib/bb/fetch2/git.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index 534c93d..d25c16e 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -472,7 +472,17 @@ class Git(FetchMethod):
             bb.utils.mkdirhier(destdir)
             runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=destdir)
         else:
-            runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, ud.cloneflags, ud.clonedir, destdir), d)
+            try:
+                runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, ud.cloneflags, ud.clonedir, destdir), d)
+            except bb.fetch2.FetchError:
+                # try to recover by pruning deleted remote branches which
+                # make cloning local git tree fail in git 2.7.x but not in
+                # git 1.9.x
+                try:
+                    runfetchcmd("%s -C %s remote prune origin" % (ud.basecmd, ud.clonedir), d)
+                except bb.fetch2.FetchError:
+                    pass
+                runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, ud.cloneflags, ud.clonedir, destdir), d)
 
         repourl = self._get_repo_url(ud)
         runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d, workdir=destdir)
-- 
1.9.1




More information about the bitbake-devel mailing list