diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index 1d17075dae0f145848ac0659b7217ed40876f650..459e4b99445a7f96ccc7737ece63dc2e46ce714a 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -385,6 +385,18 @@ describe('util/git/index', () => { }); }); + describe('hasDiff(sourceRef, targetRef)', () => { + it('compare without changes', () => { + return expect(git.hasDiff('HEAD', 'HEAD')).resolves.toBeFalse(); + }); + + it('compare with changes', () => { + return expect( + git.hasDiff('origin/master', 'origin/renovate/future_branch') + ).resolves.toBeTrue(); + }); + }); + describe('commitFiles({branchName, files, message})', () => { it('creates file', async () => { const file: FileChange = { diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 1b2c749cfb77631f57e26e43fe017b69db949953..4698779d97765c422a9ab90c7e6967609636c428 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -857,10 +857,13 @@ export async function getFile( } } -export async function hasDiff(branchName: string): Promise<boolean> { +export async function hasDiff( + sourceRef: string, + targetRef: string +): Promise<boolean> { await syncGit(); try { - return (await gitRetry(() => git.diff(['HEAD', branchName]))) !== ''; + return (await gitRetry(() => git.diff([sourceRef, targetRef]))) !== ''; } catch (err) { return true; } @@ -987,7 +990,7 @@ export async function prepareCommit({ { deletedFiles, ignoredFiles, result: commitRes }, `git commit` ); - if (!force && !(await hasDiff(`origin/${branchName}`))) { + if (!force && !(await hasDiff('HEAD', `origin/${branchName}`))) { logger.debug( { branchName, deletedFiles, addedModifiedFiles, ignoredFiles }, 'No file changes detected. Skipping commit'