From a64507ac52fdcde0c211a2ab477bd0aaa6ac2362 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Wed, 17 Oct 2018 12:19:02 +0200
Subject: [PATCH] fix: properly await all repository cleanups

---
 lib/workers/repository/index.js | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/workers/repository/index.js b/lib/workers/repository/index.js
index ac8e98df42..4764c0435e 100644
--- a/lib/workers/repository/index.js
+++ b/lib/workers/repository/index.js
@@ -20,6 +20,7 @@ async function renovateRepository(repoConfig) {
   logger.setMeta({ repository: config.repository });
   logger.info('Renovating repository');
   logger.trace({ config });
+  let repoResult;
   try {
     if (process.env.RENOVATE_TMPDIR) {
       process.env.TMPDIR = process.env.RENOVATE_TMPDIR;
@@ -37,14 +38,15 @@ async function renovateRepository(repoConfig) {
     await ensureOnboardingPr(config, packageFiles, branches);
     await ensureMasterIssue(config, branches);
     await finaliseRepo(config, branchList);
-    return processResult(config, res);
+    repoResult = processResult(config, res);
   } catch (err) /* istanbul ignore next */ {
-    return processResult(config, await handleError(config, err));
-  } finally {
-    platform.cleanRepo();
-    if (config.localDir && !config.persistRepoData) {
-      await fs.remove(config.localDir);
-    }
-    logger.info('Finished repository');
+    const errorRes = await handleError(config, err);
+    repoResult = processResult(config, errorRes);
+  }
+  await platform.cleanRepo();
+  if (config.localDir && !config.persistRepoData) {
+    await fs.remove(config.localDir);
   }
+  logger.info('Finished repository');
+  return repoResult;
 }
-- 
GitLab