diff --git a/lib/util/git/behind-base-branch-cache.spec.ts b/lib/util/git/behind-base-branch-cache.spec.ts index e711c11cc25c11c7d1384de97fa123d2f69a91ec..30d7fa9a6b1320bfb02548db0feec46045836a96 100644 --- a/lib/util/git/behind-base-branch-cache.spec.ts +++ b/lib/util/git/behind-base-branch-cache.spec.ts @@ -1,4 +1,4 @@ -import { mocked } from '../../../test/util'; +import { mocked, partial } from '../../../test/util'; import * as _repositoryCache from '../cache/repository'; import type { BranchCache, RepoCacheData } from '../cache/repository/types'; import { getCachedBehindBaseResult } from './behind-base-branch-cache'; @@ -23,6 +23,17 @@ describe('util/git/behind-base-branch-cache', () => { expect(getCachedBehindBaseResult('foo', '111')).toBeNull(); }); + it('returns null if cache is partially defined', () => { + const branchName = 'branchName'; + const branchCache = partial<BranchCache>({ + branchName, + isModified: false, + }); + const repoCache: RepoCacheData = { branches: [branchCache] }; + repositoryCache.getCache.mockReturnValue(repoCache); + expect(getCachedBehindBaseResult(branchName, '111')).toBeNull(); + }); + it('returns true if target SHA has changed', () => { repoCache.branches = [ { branchName: 'foo', sha: 'aaa', parentSha: '222' } as BranchCache, diff --git a/lib/util/git/behind-base-branch-cache.ts b/lib/util/git/behind-base-branch-cache.ts index 5b9677dbe6793d51e7dae27ee75c7f5ab16456ef..6283062df78fac8deada91cfa472962b72f2703a 100644 --- a/lib/util/git/behind-base-branch-cache.ts +++ b/lib/util/git/behind-base-branch-cache.ts @@ -12,7 +12,7 @@ export function getCachedBehindBaseResult( (branch) => branch.branchName === branchName ); - if (!cachedBranch) { + if (!cachedBranch?.parentSha) { return null; } diff --git a/lib/util/git/index.spec.ts b/lib/util/git/index.spec.ts index ca69d170d0fc27dacc2f2ccb8d2ac4f77130e57f..52159d6073583d1c42f685ca88e1f785b14c508d 100644 --- a/lib/util/git/index.spec.ts +++ b/lib/util/git/index.spec.ts @@ -1,7 +1,7 @@ import fs from 'fs-extra'; import Git from 'simple-git'; import tmp from 'tmp-promise'; -import { mocked } from '../../../test/util'; +import { mocked, partial } from '../../../test/util'; import { GlobalConfig } from '../../config/global'; import { CONFIG_VALIDATION, @@ -258,14 +258,13 @@ describe('util/git/index', () => { }); it('should return result even if non-default and not under branchPrefix', async () => { - const parentSha = await git.getBranchParentSha('develop'); + const parentSha = 'SHA'; + const branchCache = partial<BranchCache>({ + branchName: 'develop', + parentSha: parentSha, + }); repoCache.getCache.mockReturnValueOnce({}).mockReturnValueOnce({ - branches: [ - { - branchName: 'develop', - parentSha: parentSha, - } as BranchCache, - ], + branches: [branchCache], }); expect(await git.isBranchBehindBase('develop')).toBeTrue(); expect(await git.isBranchBehindBase('develop')).toBeTrue(); // cache