From 00c74a9ca2df9f105554b9de50edab7365f430c6 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Mon, 28 Mar 2022 17:44:40 +0200 Subject: [PATCH] fix(git): treat stale rejection as REPOSITORY_CHANGED (#14829) --- lib/util/git/error.ts | 1 - lib/util/git/index.ts | 27 +++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/util/git/error.ts b/lib/util/git/error.ts index 1d16ca0356..89defb295d 100644 --- a/lib/util/git/error.ts +++ b/lib/util/git/error.ts @@ -22,7 +22,6 @@ export function checkForPlatformFailure(err: Error): Error | null { 'early EOF', 'fatal: bad config', // .gitmodules problem 'expected flush after ref listing', - '[rejected] (stale info)', ]; for (const errorStr of externalHostFailureStrings) { if (err.message.includes(errorStr)) { diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 58ee277cca..fb16828b3e 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -982,18 +982,25 @@ export async function fetchCommit({ export async function commitFiles( commitConfig: CommitFilesConfig ): Promise { - const commitResult = await prepareCommit(commitConfig); - if (commitResult) { - const pushResult = await pushCommit(commitConfig); - if (pushResult) { - const { branchName } = commitConfig; - const { commitSha } = commitResult; - config.branchCommits[branchName] = commitSha; - config.branchIsModified[branchName] = false; - return commitSha; + try { + const commitResult = await prepareCommit(commitConfig); + if (commitResult) { + const pushResult = await pushCommit(commitConfig); + if (pushResult) { + const { branchName } = commitConfig; + const { commitSha } = commitResult; + config.branchCommits[branchName] = commitSha; + config.branchIsModified[branchName] = false; + return commitSha; + } } + return null; + } catch (err) /* istanbul ignore next */ { + if (err.message.includes('[rejected] (stale info)')) { + throw new Error(REPOSITORY_CHANGED); + } + throw err; } - return null; } export function getUrl({