diff --git a/__test__/git-command-manager.test.ts b/__test__/git-command-manager.test.ts index e669c0f..6ae1329 100644 --- a/__test__/git-command-manager.test.ts +++ b/__test__/git-command-manager.test.ts @@ -403,6 +403,72 @@ describe('Test fetchDepth and fetchTags options', () => { }) }) +describe('Test submoduleUpdate filter option', () => { + beforeEach(async () => { + mockFileExistsSync.mockReset() + mockDirectoryExistsSync.mockReset() + mockExec.mockImplementation((path: any, args: any, options: any) => { + if (args.includes('version')) { + options.listeners.stdout(Buffer.from('2.18')) + } + + return 0 + }) + }) + + afterEach(() => { + jest.clearAllMocks() + }) + + it('should call execGit with --filter when a filter option is provided', async () => { + const workingDirectory = 'test' + const lfs = false + const doSparseCheckout = false + git = await commandManager.createCommandManager( + workingDirectory, + lfs, + doSparseCheckout + ) + + await git.submoduleUpdate(1, true, 'blob:none') + + expect(mockExec).toHaveBeenCalledWith( + expect.any(String), + [ + '-c', + 'protocol.version=2', + 'submodule', + 'update', + '--init', + '--force', + '--depth=1', + '--recursive', + '--filter=blob:none' + ], + expect.any(Object) + ) + }) + + it('should call execGit without --filter when no filter option is provided', async () => { + const workingDirectory = 'test' + const lfs = false + const doSparseCheckout = false + git = await commandManager.createCommandManager( + workingDirectory, + lfs, + doSparseCheckout + ) + + await git.submoduleUpdate(0, false, undefined) + + expect(mockExec).toHaveBeenCalledWith( + expect.any(String), + ['-c', 'protocol.version=2', 'submodule', 'update', '--init', '--force'], + expect.any(Object) + ) + }) +}) + describe('repository initialization object format', () => { beforeEach(async () => { mockFileExistsSync.mockReset() diff --git a/dist/index.js b/dist/index.js index b381bd2..a48e512 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35872,7 +35872,7 @@ class GitCommandManager { } await this.execGit(args); } - async submoduleUpdate(fetchDepth, recursive) { + async submoduleUpdate(fetchDepth, recursive, filter) { const args = ['-c', 'protocol.version=2']; args.push('submodule', 'update', '--init', '--force'); if (fetchDepth > 0) { @@ -35881,6 +35881,9 @@ class GitCommandManager { if (recursive) { args.push('--recursive'); } + if (filter) { + args.push(`--filter=${filter}`); + } await this.execGit(args); } async submoduleStatus() { @@ -41888,7 +41891,7 @@ async function getSource(settings) { // Checkout submodules startGroup('Fetching submodules'); await git.submoduleSync(settings.nestedSubmodules); - await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules); + await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules, fetchOptions.filter); await git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules); endGroup(); // Persist credentials diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 36cdb47..20bea5a 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -55,7 +55,11 @@ export interface IGitCommandManager { shaExists(sha: string): Promise submoduleForeach(command: string, recursive: boolean): Promise submoduleSync(recursive: boolean): Promise - submoduleUpdate(fetchDepth: number, recursive: boolean): Promise + submoduleUpdate( + fetchDepth: number, + recursive: boolean, + filter: string | undefined + ): Promise submoduleStatus(): Promise tagExists(pattern: string): Promise tryClean(): Promise @@ -452,7 +456,11 @@ class GitCommandManager { await this.execGit(args) } - async submoduleUpdate(fetchDepth: number, recursive: boolean): Promise { + async submoduleUpdate( + fetchDepth: number, + recursive: boolean, + filter: string | undefined + ): Promise { const args = ['-c', 'protocol.version=2'] args.push('submodule', 'update', '--init', '--force') if (fetchDepth > 0) { @@ -463,6 +471,10 @@ class GitCommandManager { args.push('--recursive') } + if (filter) { + args.push(`--filter=${filter}`) + } + await this.execGit(args) } diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index b9c1d35..a4fac9f 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -281,7 +281,11 @@ export async function getSource(settings: IGitSourceSettings): Promise { // Checkout submodules core.startGroup('Fetching submodules') await git.submoduleSync(settings.nestedSubmodules) - await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules) + await git.submoduleUpdate( + settings.fetchDepth, + settings.nestedSubmodules, + fetchOptions.filter + ) await git.submoduleForeach( 'git config --local gc.auto 0', settings.nestedSubmodules