From 4675a81714716dc0c5633c35b5718cffb741631c Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 2 Nov 2018 07:10:53 +0100
Subject: [PATCH] fix(gitFs): throw repository-changed

Closes #2713
---
 lib/platform/git/storage.js | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/platform/git/storage.js b/lib/platform/git/storage.js
index df13374f4b..7bdb4af241 100644
--- a/lib/platform/git/storage.js
+++ b/lib/platform/git/storage.js
@@ -253,14 +253,22 @@ class Storage {
       message,
       parentBranch = config.baseBranch
     ) {
-      await git.reset('hard');
-      await git.checkout(['-B', branchName, 'origin/' + parentBranch]);
-      for (const file of files) {
-        await fs.writeFile(join(cwd, file.name), Buffer.from(file.contents));
+      try {
+        await git.reset('hard');
+        await git.checkout(['-B', branchName, 'origin/' + parentBranch]);
+        for (const file of files) {
+          await fs.writeFile(join(cwd, file.name), Buffer.from(file.contents));
+        }
+        await git.add(files.map(f => f.name));
+        await git.commit(message);
+        await git.push(['origin', branchName, '--force']);
+      } catch (err) /* istanbul ignore next */ {
+        logger.debug({ err }, 'Error commiting files');
+        if (err.message.includes('[remote rejected]')) {
+          throw new Error('repository-changed');
+        }
+        throw err;
       }
-      await git.add(files.map(f => f.name));
-      await git.commit(message);
-      await git.push(['origin', branchName, '--force']);
     }
 
     function cleanRepo() {}
-- 
GitLab