From c5e59fa732e99155e0a777d5bdca2503688c56a0 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Fri, 3 Apr 2020 10:59:36 +0800 Subject: [PATCH] Gather more debug data for GitWrapper clone GitWrapper._clone crashes occasionally but unfortunately the root cause is not found yet. We need more info for debugging. JIRA: COMPOSE-4219 Signed-off-by: Haibo Lin --- pungi/wrappers/scm.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pungi/wrappers/scm.py b/pungi/wrappers/scm.py index 61ad85da..9f91f920 100644 --- a/pungi/wrappers/scm.py +++ b/pungi/wrappers/scm.py @@ -34,6 +34,7 @@ class ScmBase(kobo.log.LoggingBase): def __init__(self, logger=None, command=None, compose=None): kobo.log.LoggingBase.__init__(self, logger=logger) self.command = command + self.compose = compose @retry(interval=60, timeout=300, wait_on=RuntimeError) def retry_run(self, cmd, **kwargs): @@ -159,12 +160,23 @@ class GitWrapper(ScmBase): try: run(["git", "fetch", "--depth=1", repo, branch], workdir=destdir) run(["git", "checkout", "FETCH_HEAD"], workdir=destdir) - except RuntimeError: + except RuntimeError as e: # Fetch failed, to do a full clone we add a remote to our empty # repo, get its content and check out the reference we want. - run(["git", "remote", "add", "origin", repo], workdir=destdir) - self.retry_run(["git", "remote", "update", "origin"], workdir=destdir) - run(["git", "checkout", branch], workdir=destdir) + self.log_debug( + "Trying to do a full clone because shallow clone failed: %s %s" + % (e, e.output) + ) + try: + run(["git", "remote", "add", "origin", repo], workdir=destdir) + self.retry_run(["git", "remote", "update", "origin"], workdir=destdir) + run(["git", "checkout", branch], workdir=destdir) + except RuntimeError: + debugdir = os.path.join(self.compose.topdir, os.path.basename(destdir)) + self.log_debug("Copying %s to %s for debugging" % (destdir, debugdir)) + makedirs(debugdir) + copy_all(destdir, debugdir) + raise self.run_process_command(destdir)