diff --git a/lib/platform/git/storage.js b/lib/platform/git/storage.js index df13374f4bf9eb5578856f1d28afc1756d7c1c13..7bdb4af24123eecd22b50b021c536d02d01d35f9 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() {}