Skip to content
Snippets Groups Projects
Commit 1e2c30a9 authored by Jamie Magee's avatar Jamie Magee Committed by Rhys Arkins
Browse files

fix: warn if force push commit has no diff (#5099)


Co-authored-by: default avatarRhys Arkins <rhys@arkins.net>
parent 982d5e9d
No related branches found
No related tags found
No related merge requests found
...@@ -475,6 +475,14 @@ export class Storage { ...@@ -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({ async commitFilesToBranch({
branchName, branchName,
files, files,
...@@ -519,6 +527,12 @@ export class Storage { ...@@ -519,6 +527,12 @@ export class Storage {
} }
} }
await this._git!.commit(message); 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}`, { await this._git!.push('origin', `${branchName}:${branchName}`, {
'--force': true, '--force': true,
'-u': true, '-u': true,
......
...@@ -263,6 +263,21 @@ describe('platform/git/storage', () => { ...@@ -263,6 +263,21 @@ describe('platform/git/storage', () => {
message: 'Update something', 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()', () => { describe('getCommitMessages()', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment