From 085ce43a4716f40bca67d5c580528fbb23720373 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 10 Sep 2018 11:34:03 +0200
Subject: [PATCH] refactor(gitfs): determineBaseBranch

---
 lib/platform/git/storage.js | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/platform/git/storage.js b/lib/platform/git/storage.js
index 754065eef5..73e8f019e4 100644
--- a/lib/platform/git/storage.js
+++ b/lib/platform/git/storage.js
@@ -40,6 +40,14 @@ class Storage {
       );
       const gitHead = path.join(repoDir, '.git/HEAD');
       let clone = true;
+      async function determineBaseBranch() {
+        // see https://stackoverflow.com/a/44750379/1438522
+        config.baseBranch =
+          config.baseBranch ||
+          (await git.raw(['symbolic-ref', 'refs/remotes/origin/HEAD']))
+            .replace('refs/remotes/origin/', '')
+            .trim();
+      }
       // istanbul ignore if
       if (process.env.NODE_ENV !== 'test' && (await fs.exists(gitHead))) {
         try {
@@ -75,12 +83,7 @@ class Storage {
         await git.raw(['config', 'commit.gpgsign', 'false']);
       }
 
-      // see https://stackoverflow.com/a/44750379/1438522
-      config.baseBranch =
-        config.baseBranch ||
-        (await git.raw(['symbolic-ref', 'refs/remotes/origin/HEAD']))
-          .replace('refs/remotes/origin/', '')
-          .trim();
+      await determineBaseBranch();
     }
 
     async function createBranch(branchName, sha) {
-- 
GitLab