diff --git a/lib/config/common.ts b/lib/config/common.ts index 97e2e267d845cd9b569d3e5aef7fbe37a32f4f86..32b7820eaae3947dc7f020b94c8623e3d5d2dfe1 100644 --- a/lib/config/common.ts +++ b/lib/config/common.ts @@ -135,7 +135,6 @@ export interface RenovateConfig depName?: string; baseBranches?: string[]; baseBranch?: string; - baseBranchSha?: string; defaultBranch?: string; branchList?: string[]; description?: string | string[]; diff --git a/lib/workers/repository/init/config.ts b/lib/workers/repository/init/config.ts index 0c42080fa380a1827af62fb9e16bf375f421078a..0422ae6acf3fa985360bc40e47033c4bffbf04fe 100644 --- a/lib/workers/repository/init/config.ts +++ b/lib/workers/repository/init/config.ts @@ -11,7 +11,7 @@ import { CONFIG_VALIDATION } from '../../../constants/error-messages'; import * as npmApi from '../../../datasource/npm'; import { logger } from '../../../logger'; import { readLocalFile } from '../../../util/fs'; -import { checkoutBranch, getFileList } from '../../../util/git'; +import { getFileList } from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { checkOnboardingBranch } from '../onboarding/branch'; import { RepoFileConfig } from './common'; @@ -220,7 +220,6 @@ export async function getRepoConfig( ): Promise<RenovateConfig> { let config = { ...config_ }; config.baseBranch = config.defaultBranch; - config.baseBranchSha = await checkoutBranch(config.baseBranch); config = await checkOnboardingBranch(config); config = await mergeRenovateConfig(config); config.semanticCommits = diff --git a/lib/workers/repository/process/extract-update.spec.ts b/lib/workers/repository/process/extract-update.spec.ts index d2698d8919d034de4d1bf551cc0fb5c192caf205..2ba50adbcb38f31d4195bbb484f43f80422f2643 100644 --- a/lib/workers/repository/process/extract-update.spec.ts +++ b/lib/workers/repository/process/extract-update.spec.ts @@ -1,5 +1,5 @@ import hasha from 'hasha'; -import { mocked } from '../../../../test/util'; +import { git, mocked } from '../../../../test/util'; import * as _repositoryCache from '../../../util/cache/repository'; import * as _branchify from '../updates/branchify'; import { extract, lookup, update } from './extract-update'; @@ -10,6 +10,7 @@ jest.mock('./fetch'); jest.mock('../updates/branchify'); jest.mock('../extract'); jest.mock('../../../util/cache/repository'); +jest.mock('../../../util/git'); const branchify = mocked(_branchify); const repositoryCache = mocked(_repositoryCache); @@ -27,6 +28,7 @@ describe('workers/repository/process/extract-update', () => { suppressNotifications: ['deprecationWarningIssues'], }; repositoryCache.getCache.mockReturnValueOnce({ scan: {} }); + git.checkoutBranch.mockResolvedValueOnce('abc123'); const packageFiles = await extract(config); const res = await lookup(config, packageFiles); expect(res).toMatchSnapshot(); @@ -38,6 +40,7 @@ describe('workers/repository/process/extract-update', () => { repoIsOnboarded: true, suppressNotifications: ['deprecationWarningIssues'], }; + git.checkoutBranch.mockResolvedValueOnce('abc123'); repositoryCache.getCache.mockReturnValueOnce({ scan: {} }); const packageFiles = await extract(config); expect(packageFiles).toMatchSnapshot(); @@ -48,17 +51,18 @@ describe('workers/repository/process/extract-update', () => { repoIsOnboarded: true, suppressNotifications: ['deprecationWarningIssues'], baseBranch: 'master', - baseBranchSha: 'abc123', }; repositoryCache.getCache.mockReturnValueOnce({ scan: { master: { - sha: config.baseBranchSha, + sha: 'abc123', configHash: hasha(JSON.stringify(config)), packageFiles, }, }, }); + git.getBranchCommit.mockReturnValueOnce('abc123'); + git.checkoutBranch.mockResolvedValueOnce('abc123'); const res = await extract(config); expect(res).toEqual(packageFiles); }); diff --git a/lib/workers/repository/process/extract-update.ts b/lib/workers/repository/process/extract-update.ts index 09e60b827426a734f569cf11583dd074fa372c47..f06fc4f1100b224173818312e62b5939c2836c85 100644 --- a/lib/workers/repository/process/extract-update.ts +++ b/lib/workers/repository/process/extract-update.ts @@ -4,6 +4,7 @@ import { RenovateConfig } from '../../../config'; import { logger } from '../../../logger'; import { PackageFile } from '../../../manager/common'; import { getCache } from '../../../util/cache/repository'; +import { checkoutBranch, getBranchCommit } from '../../../util/git'; import { BranchConfig } from '../../common'; import { extractAllDependencies } from '../extract'; import { branchifyUpgrades } from '../updates/branchify'; @@ -50,7 +51,8 @@ export async function extract( config: RenovateConfig ): Promise<Record<string, PackageFile[]>> { logger.debug('extract()'); - const { baseBranch, baseBranchSha } = config; + const { baseBranch } = config; + const baseBranchSha = getBranchCommit(baseBranch); let packageFiles; const cache = getCache(); const cachedExtract = cache?.scan?.[baseBranch]; @@ -63,6 +65,7 @@ export async function extract( logger.debug({ baseBranch, baseBranchSha }, 'Found cached extract'); packageFiles = cachedExtract.packageFiles; } else { + await checkoutBranch(baseBranch); packageFiles = await extractAllDependencies(config); cache.scan[baseBranch] = { sha: baseBranchSha, diff --git a/lib/workers/repository/process/index.ts b/lib/workers/repository/process/index.ts index cd7fcdf73183e90750af8ba4e5dfc6d0c79f903f..feb8671e4ab407c23bc2172546ac9a9397460ce2 100644 --- a/lib/workers/repository/process/index.ts +++ b/lib/workers/repository/process/index.ts @@ -2,23 +2,22 @@ import { RenovateConfig, mergeChildConfig } from '../../../config'; import { logger } from '../../../logger'; import { PackageFile } from '../../../manager/common'; import { platform } from '../../../platform'; -import { branchExists, checkoutBranch } from '../../../util/git'; +import { branchExists } from '../../../util/git'; import { addSplit } from '../../../util/split'; import { BranchConfig } from '../../common'; import { ExtractResult, extract, lookup, update } from './extract-update'; import { WriteUpdateResult } from './write'; -async function getBaseBranchConfig( +function getBaseBranchConfig( baseBranch: string, config: RenovateConfig -): Promise<RenovateConfig> { +): RenovateConfig { logger.debug(`baseBranch: ${baseBranch}`); const baseBranchConfig = mergeChildConfig(config, { baseBranch }); if (config.baseBranches.length > 1) { baseBranchConfig.branchPrefix += `${baseBranch}-`; baseBranchConfig.hasBaseBranches = true; } - baseBranchConfig.baseBranchSha = await checkoutBranch(baseBranch); return baseBranchConfig; } @@ -67,7 +66,7 @@ export async function extractDependencies( const extracted: Record<string, Record<string, PackageFile[]>> = {}; for (const baseBranch of config.baseBranches) { if (branchExists(baseBranch)) { - const baseBranchConfig = await getBaseBranchConfig(baseBranch, config); + const baseBranchConfig = getBaseBranchConfig(baseBranch, config); extracted[baseBranch] = await extract(baseBranchConfig); } else { logger.warn({ baseBranch }, 'Base branch does not exist - skipping'); @@ -76,7 +75,7 @@ export async function extractDependencies( addSplit('extract'); for (const baseBranch of config.baseBranches) { if (branchExists(baseBranch)) { - const baseBranchConfig = await getBaseBranchConfig(baseBranch, config); + const baseBranchConfig = getBaseBranchConfig(baseBranch, config); const packageFiles = extracted[baseBranch]; const baseBranchRes = await lookup(baseBranchConfig, packageFiles); res.branches = res.branches.concat(baseBranchRes?.branches);