Skip to content

Commit

Permalink
fix: check branchExisst before checking cache
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Jul 13, 2022
1 parent 4161930 commit 213bc9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
20 changes: 5 additions & 15 deletions lib/util/git/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ describe('util/git/index', () => {
});
});

describe('isBranchModified()', () => {
// eslint-disable-next-line jest/no-focused-tests
describe.only('isBranchModified()', () => {
beforeEach(() => {
modifiedCache.getCachedModifiedResult.mockReturnValue(null);
});
Expand All @@ -277,20 +278,9 @@ describe('util/git/index', () => {
expect(await git.isBranchModified('renovate/custom_author')).toBeTrue();
});

describe('Cache', () => {
beforeEach(() => {
modifiedCache.getCachedModifiedResult.mockReturnValue(false);
});

it('should return false when branch is not found', async () => {
expect(await git.isBranchModified('renovate/not_found')).toBeFalse();
});

it('should return false when author matches', async () => {
expect(
await git.isBranchModified('renovate/future_branch')
).toBeFalse();
});
it('should return value stored in modifiedCacheResult', async () => {
modifiedCache.getCachedModifiedResult.mockReturnValue(true);
expect(await git.isBranchModified('renovate/future_branch')).toBeTrue();
});
});

Expand Down
14 changes: 7 additions & 7 deletions lib/util/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,13 @@ export async function isBranchStale(branchName: string): Promise<boolean> {
}

export async function isBranchModified(branchName: string): Promise<boolean> {
if (!branchExists(branchName)) {
logger.debug(
{ branchName },
'Branch does not exist - cannot check isModified'
);
return false;
}
// First check local config
if (config.branchIsModified[branchName] !== undefined) {
return config.branchIsModified[branchName];
Expand All @@ -582,13 +589,6 @@ export async function isBranchModified(branchName: string): Promise<boolean> {
}

await syncGit();
if (!branchExists(branchName)) {
logger.debug(
{ branchName },
'Branch does not exist - cannot check isModified'
);
return false;
}
// Retrieve the author of the most recent commit
let lastAuthor: string | undefined;
try {
Expand Down

0 comments on commit 213bc9e

Please sign in to comment.