diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index 0e0e40d5763cd0be750bbaf68e72e35aa2a043e1..1dcdcf5cdeb4ea43150b7f24a5c1d3e447466bd3 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -475,6 +475,14 @@ export class Storage { } } + async hasDiff(branchName: string): Promise<boolean> { + try { + return (await this._git!.diff(['HEAD', branchName])) !== ''; + } catch (err) { + return true; + } + } + async commitFilesToBranch({ branchName, files, @@ -519,6 +527,12 @@ export class Storage { } } await this._git!.commit(message); + if (!(await this.hasDiff(`origin/${branchName}`))) { + logger.warn( + { branchName, fileNames }, + 'No file changes detected. Is this an empty force push?' + ); + } await this._git!.push('origin', `${branchName}:${branchName}`, { '--force': true, '-u': true, diff --git a/test/platform/git/storage.spec.ts b/test/platform/git/storage.spec.ts index fb8ab75a0c43ecfc9adcfe854bcded0973579cdf..8156f9a7f483d2f124e2ae00ab98aae8d935e163 100644 --- a/test/platform/git/storage.spec.ts +++ b/test/platform/git/storage.spec.ts @@ -263,6 +263,21 @@ describe('platform/git/storage', () => { message: 'Update something', }); }); + it('does not push when no diff', async () => { + const branchName = 'renovate/something'; + const local = Git(tmpDir.path); + await local.push('origin', `master:${branchName}`); + await local.fetch([ + 'origin', + `refs/heads/${branchName}:refs/remotes/origin/${branchName}`, + ]); + const files = []; + await git.commitFilesToBranch({ + branchName, + files, + message: 'Update something', + }); + }); }); describe('getCommitMessages()', () => {