From ac7af06d808998f921ab0d2667ea9471e9577200 Mon Sep 17 00:00:00 2001 From: Xavier Chapron Date: Fri, 29 Oct 2021 10:54:32 +0200 Subject: [PATCH] Add reset and clean for submodules --- dist/index.js | 22 ++++++++++++++++++++++ src/git-command-manager.ts | 22 ++++++++++++++++++++++ src/git-source-provider.ts | 2 ++ 3 files changed, 46 insertions(+) diff --git a/dist/index.js b/dist/index.js index 7155f1c..9ec08b0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7101,6 +7101,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]); @@ -7416,6 +7436,8 @@ function getSource(settings) { core.startGroup('Fetching submodules'); yield git.submoduleSync(settings.nestedSubmodules); yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules); + yield git.submoduleReset(settings.nestedSubmodules); + yield git.submoduleClean(settings.nestedSubmodules); yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules); core.endGroup(); // Persist credentials diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 409a161..6932e96 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -40,6 +40,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 @@ -324,6 +326,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..b95ce3a 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -183,6 +183,8 @@ export async function getSource(settings: IGitSourceSettings): Promise { settings.fetchDepth, settings.nestedSubmodules ) + await git.submoduleReset(settings.nestedSubmodules) + await git.submoduleClean(settings.nestedSubmodules) await git.submoduleForeach( 'git config --local gc.auto 0', settings.nestedSubmodules