diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index e14e948..cf42627 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -738,6 +738,8 @@ async function setup(testName: string): Promise { }), submoduleSync: jest.fn(), submoduleUpdate: jest.fn(), + submoduleReset: jest.fn(), + submoduleClean: jest.fn(), tagExists: jest.fn(), tryClean: jest.fn(), tryConfigUnset: jest.fn( diff --git a/__test__/git-directory-helper.test.ts b/__test__/git-directory-helper.test.ts index 70849b5..e6d3cd0 100644 --- a/__test__/git-directory-helper.test.ts +++ b/__test__/git-directory-helper.test.ts @@ -423,6 +423,8 @@ async function setup(testName: string): Promise { submoduleForeach: jest.fn(), submoduleSync: jest.fn(), submoduleUpdate: jest.fn(), + submoduleReset: jest.fn(), + submoduleClean: jest.fn(), tagExists: jest.fn(), tryClean: jest.fn(async () => { return true diff --git a/dist/index.js b/dist/index.js index 271b054..4ed111f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7109,6 +7109,26 @@ class GitCommandManager { yield this.execGit(args); }); } + submoduleReset(recursive) { + return __awaiter(this, void 0, void 0, function* () { + const args = ['submodule', 'foreach']; + if (recursive) { + args.push('--recursive'); + } + args.push('git reset --hard'); + yield this.execGit(args); + }); + } + submoduleClean(recursive) { + return __awaiter(this, void 0, void 0, function* () { + const args = ['submodule', 'foreach']; + if (recursive) { + args.push('--recursive'); + } + args.push('git clean -ffdx'); + yield this.execGit(args); + }); + } tagExists(pattern) { return __awaiter(this, void 0, void 0, function* () { const output = yield this.execGit(['tag', '--list', pattern]); @@ -7420,6 +7440,11 @@ function getSource(settings) { core.startGroup('Setting up auth for fetching submodules'); yield authHelper.configureGlobalAuth(); core.endGroup(); + // Clean existing submodules + if (settings.clean) { + yield git.submoduleReset(settings.nestedSubmodules); + yield git.submoduleClean(settings.nestedSubmodules); + } // Checkout submodules core.startGroup('Fetching submodules'); yield git.submoduleSync(settings.nestedSubmodules); diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 699a963..faacc21 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -41,6 +41,8 @@ export interface IGitCommandManager { submoduleForeach(command: string, recursive: boolean): Promise submoduleSync(recursive: boolean): Promise submoduleUpdate(fetchDepth: number, recursive: boolean): Promise + submoduleReset(recursive: boolean): Promise + submoduleClean(recursive: boolean): Promise tagExists(pattern: string): Promise tryClean(): Promise tryConfigUnset(configKey: string, globalConfig?: boolean): Promise @@ -326,6 +328,26 @@ class GitCommandManager { await this.execGit(args) } + async submoduleReset(recursive: boolean): Promise { + const args = ['submodule', 'foreach'] + if (recursive) { + args.push('--recursive') + } + args.push('git reset --hard') + + await this.execGit(args) + } + + async submoduleClean(recursive: boolean): Promise { + const args = ['submodule', 'foreach'] + if (recursive) { + args.push('--recursive') + } + args.push('git clean -ffdx') + + await this.execGit(args) + } + async tagExists(pattern: string): Promise { const output = await this.execGit(['tag', '--list', pattern]) return !!output.stdout.trim() diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 42a12e0..a96afba 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -176,6 +176,13 @@ export async function getSource(settings: IGitSourceSettings): Promise { await authHelper.configureGlobalAuth() core.endGroup() + // Clean existing submodules + if (settings.clean) + { + await git.submoduleReset(settings.nestedSubmodules) + await git.submoduleClean(settings.nestedSubmodules) + } + // Checkout submodules core.startGroup('Fetching submodules') await git.submoduleSync(settings.nestedSubmodules)