diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index 87aae87eb3ae46..4574508925a0b9 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -136,6 +136,9 @@ describe('platform/git', () => { }); }); describe('isBranchModified()', () => { + it('should return false when branch is not found', async () => { + expect(await git.isBranchModified('renovate/not_found')).toBe(false); + }); it('should return true when author matches', async () => { expect(await git.isBranchModified('renovate/future_branch')).toBe(false); expect(await git.isBranchModified('renovate/future_branch')).toBe(false); diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 5885488c3a23f0..d43b0b8a3f631a 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -401,6 +401,13 @@ export async function isBranchModified(branchName: string): Promise { if (config.branchIsModified[branchName] !== undefined) { return config.branchIsModified[branchName]; } + if (!branchExists(branchName)) { + logger.debug( + { branchName }, + 'Branch does not exist - cannot check isModified' + ); + return false; + } // Retrieve the author of the most recent commit const lastAuthor = ( await git.raw([