From 95003a6c045bc21f0699dea5f60f03a0c8fc2a1a Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Sun, 10 Oct 2021 17:24:54 +0200
Subject: [PATCH] fix(git): catch common branch push errors (#12096)

---
 lib/util/git/index.ts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts
index ebcbcf1981..3b66f06f96 100644
--- a/lib/util/git/index.ts
+++ b/lib/util/git/index.ts
@@ -840,6 +840,20 @@ export async function commitFiles({
       logger.error({ err }, 'Error committing files.');
       return null;
     }
+    if (err.message.includes('[rejected] (stale info)')) {
+      logger.info(
+        'Branch update was rejected because local copy is not up-to-date.'
+      );
+      return null;
+    }
+    if (err.message.includes('denying non-fast-forward')) {
+      logger.debug({ err }, 'Permission denied to update branch');
+      const error = new Error(CONFIG_VALIDATION);
+      error.validationSource = branchName;
+      error.validationError = 'Force push denied';
+      error.validationMessage = `Renovate is unable to update branch(es) due to force pushes being disallowed.`;
+      throw error;
+    }
     logger.debug({ err }, 'Unknown error committing files');
     // We don't know why this happened, so this will cause bubble up to a branch error
     throw err;
-- 
GitLab