diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 711fd0ba3d397192ec4ccba6c0d9123888633d60..903c723509005b678724481ee715ed34ab945782 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -48,6 +48,7 @@ interface Config { project: string; azureWorkItemId: string; prList: Pr[]; + fileList: null; repository: string; } @@ -181,8 +182,10 @@ export function getRepoForceRebase(): Promise<boolean> { // Search -export /* istanbul ignore next */ function getFileList(): Promise<string[]> { - return config.storage.getFileList(); +export /* istanbul ignore next */ function getFileList( + branchName?: string +): Promise<string[]> { + return config.storage.getFileList(branchName); } export /* istanbul ignore next */ async function setBaseBranch( @@ -191,7 +194,9 @@ export /* istanbul ignore next */ async function setBaseBranch( logger.debug(`Setting baseBranch to ${branchName}`); config.baseBranch = branchName; delete config.baseCommitSHA; + delete config.fileList; const baseBranchSha = await config.storage.setBaseBranch(branchName); + await getFileList(branchName); return baseBranchSha; } diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 3cdd5b269b077594f71a5b39d36f9b69af0e34f6..2d5f726bc57fb20055ebb46251ac061fabd5844e 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -49,6 +49,7 @@ interface BbsConfig { baseBranch: string; bbUseDefaultReviewers: boolean; defaultBranch: string; + fileList: any[]; mergeMethod: string; owner: string; prList: Pr[]; @@ -272,8 +273,11 @@ export /* istanbul ignore next */ function setBranchPrefix( // Search // Get full file list -export function getFileList(): Promise<string[]> { - return config.storage.getFileList(); +export function getFileList( + branchName: string = config.baseBranch +): Promise<string[]> { + logger.debug(`getFileList(${branchName})`); + return config.storage.getFileList(branchName); } // Branch diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index a7c0f31919114b9e358a7b8b59b2f94f26c3915f..d516a162c3c8a94e6e4dddefedfecd47b49f91b0 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -173,8 +173,8 @@ export function getRepoForceRebase(): Promise<boolean> { // Search // Get full file list -export function getFileList(): Promise<string[]> { - return config.storage.getFileList(); +export function getFileList(branchName?: string): Promise<string[]> { + return config.storage.getFileList(branchName); } export async function setBaseBranch( @@ -182,7 +182,10 @@ export async function setBaseBranch( ): Promise<string> { logger.debug(`Setting baseBranch to ${branchName}`); config.baseBranch = branchName; + delete config.baseCommitSHA; + delete config.fileList; const baseBranchSha = await config.storage.setBaseBranch(branchName); + await getFileList(branchName); return baseBranchSha; } @@ -830,6 +833,7 @@ export async function mergePr( }, } ); + delete config.baseCommitSHA; logger.debug('Automerging succeeded'); } catch (err) /* istanbul ignore next */ { return false; diff --git a/lib/platform/bitbucket/utils.ts b/lib/platform/bitbucket/utils.ts index c4721cbbeeedfbc04c282ff9fed7af7776868fdb..1461bf2860470732994ed016edb1ee53ea2c3d1e 100644 --- a/lib/platform/bitbucket/utils.ts +++ b/lib/platform/bitbucket/utils.ts @@ -9,6 +9,7 @@ export interface Config { baseBranch: string; baseCommitSHA: string; defaultBranch: string; + fileList: any[]; has_issues: boolean; mergeMethod: string; owner: string; diff --git a/lib/platform/git/__snapshots__/storage.spec.ts.snap b/lib/platform/git/__snapshots__/storage.spec.ts.snap index 84944dea609d2df30ddc2dcb288f7e4eee03e350..28860dd7e40f4c22008d594759b95634a678465d 100644 --- a/lib/platform/git/__snapshots__/storage.spec.ts.snap +++ b/lib/platform/git/__snapshots__/storage.spec.ts.snap @@ -11,24 +11,21 @@ Array [ exports[`platform/git/storage getFile(filePath, branchName) returns null for 404 1`] = `[Error: repository-changed]`; -exports[`platform/git/storage getFileList() returns cached version 1`] = ` +exports[`platform/git/storage getFileList() defaults to master 1`] = `Array []`; + +exports[`platform/git/storage getFileList() should exclude submodules 1`] = ` Array [ + ".gitmodules", "file_to_delete", "master_file", "past_file", ] `; -exports[`platform/git/storage getFileList() returns from other branch 1`] = ` -Array [ - "past_file", -] -`; - -exports[`platform/git/storage getFileList() should exclude submodules 1`] = ` +exports[`platform/git/storage getFileList() should return the correct files 1`] = ` Array [ - ".gitmodules", "file_to_delete", + "future_file", "master_file", "past_file", ] diff --git a/lib/platform/git/storage.spec.ts b/lib/platform/git/storage.spec.ts index 5f116968a6b39749255bcfe46e22a0a600dc6e70..30c12c7148a66a18f63eeddb260eb0a54b3c2b95 100644 --- a/lib/platform/git/storage.spec.ts +++ b/lib/platform/git/storage.spec.ts @@ -82,6 +82,12 @@ describe('platform/git/storage', () => { }); }); describe('getFileList()', () => { + it('returns empty array if error', async () => { + expect(await git.getFileList('not_found')).toEqual([]); + }); + it('should return the correct files', async () => { + expect(await git.getFileList('renovate/future_branch')).toMatchSnapshot(); + }); it('should exclude submodules', async () => { const repo = Git(base.path).silent(true); await repo.submoduleAdd(base.path, 'submodule'); @@ -91,18 +97,12 @@ describe('platform/git/storage', () => { url: base.path, }); expect(await fs.exists(tmpDir.path + '/.gitmodules')).toBeTruthy(); - expect(await git.getFileList()).toMatchSnapshot(); + expect(await git.getFileList('master')).toMatchSnapshot(); await repo.reset(['--hard', 'HEAD^']); }); - it('returns cached version', async () => { + it('defaults to master', async () => { expect(await git.getFileList()).toMatchSnapshot(); }); - it('returns from other branch', async () => { - await git.setBaseBranch('develop'); - const res = await git.getFileList(); - expect(res).toMatchSnapshot(); - expect(res).toHaveLength(1); - }); }); describe('branchExists(branchName)', () => { it('should return true if found', async () => { diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts index 0856e19cfb91a7e959976add6776daa9da3d3e3e..2aca6841e7adecc8e736412b994a6c5586dc8b18 100644 --- a/lib/platform/git/storage.ts +++ b/lib/platform/git/storage.ts @@ -32,7 +32,7 @@ interface LocalConfig extends StorageConfig { baseBranchSha: string; branchExists: Record<string, boolean>; branchPrefix: string; - fileList?: string[]; + fileList: Record<string, Promise<string[]>>; } // istanbul ignore next @@ -109,6 +109,7 @@ export class Storage { // eslint-disable-next-line no-multi-assign const config: LocalConfig = (this._config = { ...args, + fileList: {}, } as any); // eslint-disable-next-line no-multi-assign const cwd = (this._cwd = config.localDir); @@ -259,7 +260,6 @@ export class Storage { } logger.debug(`Setting baseBranch to ${branchName}`); this._config.baseBranch = branchName; - delete this._config.fileList; try { if (branchName !== 'master') { this._config.baseBranchSha = ( @@ -305,28 +305,36 @@ export class Storage { } } - async getFileList(): Promise<string[]> { - if (!this._config.fileList) { - const submodules = await this.getSubmodules(); - const files: string = await this._git.raw([ - 'ls-tree', - '-r', - '--name-only', - 'HEAD', - ]); - // istanbul ignore else - if (files) { - this._config.fileList = files - .split('\n') - .filter(Boolean) - .filter((file: string) => - submodules.every((submodule: string) => !file.startsWith(submodule)) - ); - } else { - this._config.fileList = []; - } + async getFileList(branchName?: string): Promise<string[]> { + const branch = branchName || this._config.baseBranch; + if (this._config.fileList[branch] === undefined) { + this._config.fileList[branch] = this.getFileListInner(branchName); + } + return this._config.fileList[branch]; + } + + async getFileListInner(branch: string): Promise<string[]> { + const exists = await this.branchExists(branch); + if (!exists) { + return []; } - return this._config.fileList; + const submodules = await this.getSubmodules(); + const files: string = await this._git.raw([ + 'ls-tree', + '-r', + '--name-only', + 'origin/' + branch, + ]); + // istanbul ignore if + if (!files) { + return []; + } + return files + .split('\n') + .filter(Boolean) + .filter((file: string) => + submodules.every((submodule: string) => !file.startsWith(submodule)) + ); } async getSubmodules(): Promise<string[]> { diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index e50378ddf0bb80551886fe28ed9e9deaf42fa585..cbdc65eb0f66989587137973b468a97cbed6a215 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -929,7 +929,7 @@ const platform: Platform = { }, getFileList(): Promise<string[]> { - return config.storage.getFileList(); + return config.storage.getFileList(config.baseBranch); }, getAllRenovateBranches(branchPrefix: string): Promise<string[]> { diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 9a1e7d5be4647732a393087bfef798f7ccd19316..d1080f761cdad02d3226252a44c987778032ff11 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -535,8 +535,8 @@ export function setBranchPrefix(branchPrefix: string): Promise<void> { // Search // istanbul ignore next -export function getFileList(): Promise<string[]> { - return config.storage.getFileList(); +export function getFileList(branchName = config.baseBranch): Promise<string[]> { + return config.storage.getFileList(branchName); } // Branch diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index e5418ad2a4790d5216288ce16fa9af73420d9741..e3c620e7b28616ac61174eb14441640c0ed45fa6 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -286,8 +286,8 @@ export /* istanbul ignore next */ function setBranchPrefix( // Search // Get full file list -export function getFileList(): Promise<string[]> { - return config.storage.getFileList(); +export function getFileList(branchName = config.baseBranch): Promise<string[]> { + return config.storage.getFileList(branchName); } // Returns true if branch exists, otherwise false diff --git a/lib/workers/repository/extract/file-match.ts b/lib/workers/repository/extract/file-match.ts index b3a976ce0cdfa80261e819d23ced78503966c828..04e6ee64f0726a54d0f396e80b5732caf51dd095 100644 --- a/lib/workers/repository/extract/file-match.ts +++ b/lib/workers/repository/extract/file-match.ts @@ -35,6 +35,10 @@ export function filterIgnoredFiles( ); } +export function getFileList(): Promise<string[]> { + return platform.getFileList(); +} + export function getFilteredFileList( config: RenovateConfig, fileList: string[] @@ -48,7 +52,7 @@ export function getFilteredFileList( export async function getMatchingFiles( config: RenovateConfig ): Promise<string[]> { - const allFiles = await platform.getFileList(); + const allFiles = await getFileList(); const fileList = getFilteredFileList(config, allFiles); const { fileMatch, manager } = config; let matchedFiles = [];