Skip to content

Commit

Permalink
fix(git): add branchExists safety check to isBranchModified
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Sep 22, 2020
1 parent f0ba97b commit 36e2792
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/util/git/index.spec.ts
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions lib/util/git/index.ts
Expand Up @@ -401,6 +401,13 @@ export async function isBranchModified(branchName: string): Promise<boolean> {
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([
Expand Down

0 comments on commit 36e2792

Please sign in to comment.