Skip to content

Commit

Permalink
fix: don’t push empty commit (#9058)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 9, 2021
1 parent c17e409 commit 3ad3895
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/util/git/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,19 @@ describe('platform/git', () => {
files,
message: 'Update something',
});
expect(commit).not.toBeNull();
expect(commit).toBeNull();
});
it('does not push when no diff', async () => {
const branchName = 'renovate/something';
const local = Git(tmpDir.path);
await local.push('origin', `${defaultBranch}:${branchName}`);
await local.fetch([
'origin',
`refs/heads/${branchName}:refs/remotes/origin/${branchName}`,
]);
const files = [];
const files = [
{
name: 'future_file',
contents: 'future',
},
];
const commit = await git.commitFiles({
branchName,
branchName: 'renovate/future_branch',
files,
message: 'Update something',
message: 'No change update',
});
expect(commit).toBeNull();
});
Expand Down
9 changes: 9 additions & 0 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,15 @@ export async function commitFiles({
const commitRes = await git.commit(message, [], {
'--no-verify': null,
});
if (
commitRes.summary &&
commitRes.summary.changes === 0 &&
commitRes.summary.insertions === 0 &&
commitRes.summary.deletions === 0
) {
logger.warn({ commitRes }, 'Detected empty commit - aborting git push');
return null;
}
logger.debug({ result: commitRes }, `git commit`);
const commit = commitRes?.commit || 'unknown';
if (!force && !(await hasDiff(`origin/${branchName}`))) {
Expand Down

0 comments on commit 3ad3895

Please sign in to comment.