From ceebedca3fb06b9a650a33b3ee3027acbdcae4e2 Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Wed, 24 Jul 2019 17:20:17 +0200
Subject: [PATCH] fix(git): aonly allow fast-forward merge (#4169)

fix(git): aonly allow fast-forward merge
---
 lib/platform/git/storage.ts       |  2 +-
 test/platform/git/storage.spec.ts | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts
index 833fe05fa0..6aedcecb10 100644
--- a/lib/platform/git/storage.ts
+++ b/lib/platform/git/storage.ts
@@ -338,7 +338,7 @@ export class Storage {
     await this._git!.reset('hard');
     await this._git!.checkout(['-B', branchName, 'origin/' + branchName]);
     await this._git!.checkout(this._config.baseBranch);
-    await this._git!.merge([branchName]);
+    await this._git!.merge(['--ff-only', branchName]);
     await this._git!.push('origin', this._config.baseBranch);
   }
 
diff --git a/test/platform/git/storage.spec.ts b/test/platform/git/storage.spec.ts
index d9602ee0fc..b9a8d184bc 100644
--- a/test/platform/git/storage.spec.ts
+++ b/test/platform/git/storage.spec.ts
@@ -149,6 +149,20 @@ describe('platform/git/storage', () => {
     it('should throw if branch merge throws', async () => {
       await expect(git.mergeBranch('not_found')).rejects.toThrow();
     });
+    it('should throw if branch merge is stale', async () => {
+      expect.assertions(1);
+      await git.setBranchPrefix('renovate/');
+      await git.commitFilesToBranch(
+        'test',
+        [{ name: 'some-new-file', contents: 'some new-contents' }],
+        'test mesage',
+        'renovate/past_branch'
+      );
+
+      await git.setBaseBranch('master');
+
+      await expect(git.mergeBranch('test')).rejects.toThrow();
+    });
   });
   describe('deleteBranch(branchName)', () => {
     it('should send delete', async () => {
-- 
GitLab