From 3327cce30bc568727ef1f2365316866ff25d63c6 Mon Sep 17 00:00:00 2001 From: Simon Baird Date: Wed, 4 Jan 2023 22:27:46 -0500 Subject: [PATCH] Support fetching without the --progress option Setting the `progress` option to false in the `with` section of the workflow step will cause git fetch to run without `--progress`. The motivation is to be able to suppress the noisy progress status output which adds many hundreds of "remote: Counting objects: 85% (386/453)" and similar lines in the workflow log. This should be sufficient to resolve #894 and its older friends, though the solution is different to the one proposed there because it doesn't use the --quiet flag. IIUC git doesn't show the progress status by default since the output is not a terminal, so that's why removing the --progress option is all that's needed. --- README.md | 4 ++++ __test__/git-auth-helper.test.ts | 1 + action.yml | 3 +++ dist/index.js | 17 ++++++++++++----- src/git-command-manager.ts | 18 +++++++++++++++--- src/git-source-provider.ts | 6 +++--- src/git-source-settings.ts | 5 +++++ src/input-helper.ts | 5 +++++ 8 files changed, 48 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8fe140f55..6a2677cc2 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl # Default: 1 fetch-depth: '' + # Whether to show progress status output when fetching. + # Default: true + show-progress: '' + # Whether to download Git-LFS files # Default: false lfs: '' diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index b58010b7c..99c8a6370 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -801,6 +801,7 @@ async function setup(testName: string): Promise { clean: true, commit: '', fetchDepth: 1, + showProgress: true, lfs: false, submodules: false, nestedSubmodules: false, diff --git a/action.yml b/action.yml index cab09ebd3..05eb18335 100644 --- a/action.yml +++ b/action.yml @@ -56,6 +56,9 @@ inputs: fetch-depth: description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.' default: 1 + show-progress: + description: 'Whether to show progress status output when fetching.' + default: true lfs: description: 'Whether to download Git-LFS files' default: false diff --git a/dist/index.js b/dist/index.js index e6f5df8ff..e8689bb05 100644 --- a/dist/index.js +++ b/dist/index.js @@ -615,13 +615,16 @@ class GitCommandManager { return output.exitCode === 0; }); } - fetch(refSpec, fetchDepth) { + fetch(refSpec, fetchDepth, showProgress) { return __awaiter(this, void 0, void 0, function* () { const args = ['-c', 'protocol.version=2', 'fetch']; if (!refSpec.some(x => x === refHelper.tagsRefSpec)) { args.push('--no-tags'); } - args.push('--prune', '--progress', '--no-recurse-submodules'); + args.push('--prune', '--no-recurse-submodules'); + if (showProgress) { + args.push('--progress'); + } if (fetchDepth && fetchDepth > 0) { args.push(`--depth=${fetchDepth}`); } @@ -1213,17 +1216,17 @@ function getSource(settings) { if (settings.fetchDepth <= 0) { // Fetch all branches and tags let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit); - yield git.fetch(refSpec); + yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress); // When all history is fetched, the ref we're interested in may have moved to a different // commit (push or force push). If so, fetch again with a targeted refspec. if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) { refSpec = refHelper.getRefSpec(settings.ref, settings.commit); - yield git.fetch(refSpec); + yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress); } } else { const refSpec = refHelper.getRefSpec(settings.ref, settings.commit); - yield git.fetch(refSpec, settings.fetchDepth); + yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress); } core.endGroup(); // Checkout info @@ -1679,6 +1682,10 @@ function getInputs() { result.fetchDepth = 0; } core.debug(`fetch depth = ${result.fetchDepth}`); + // Show fetch progress + result.showProgress = + (core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE'; + core.debug(`show progress = ${result.showProgress}`); // LFS result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'; core.debug(`lfs = ${result.lfs}`); diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index ab07524e1..528c7412b 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -25,7 +25,11 @@ export interface IGitCommandManager { add?: boolean ): Promise configExists(configKey: string, globalConfig?: boolean): Promise - fetch(refSpec: string[], fetchDepth?: number): Promise + fetch( + refSpec: string[], + fetchDepth: number, + showProgress: boolean + ): Promise getDefaultBranch(repositoryUrl: string): Promise getWorkingDirectory(): string init(): Promise @@ -202,13 +206,21 @@ class GitCommandManager { return output.exitCode === 0 } - async fetch(refSpec: string[], fetchDepth?: number): Promise { + async fetch( + refSpec: string[], + fetchDepth: number, + showProgress: boolean + ): Promise { const args = ['-c', 'protocol.version=2', 'fetch'] if (!refSpec.some(x => x === refHelper.tagsRefSpec)) { args.push('--no-tags') } - args.push('--prune', '--progress', '--no-recurse-submodules') + args.push('--prune', '--no-recurse-submodules') + if (showProgress) { + args.push('--progress') + } + if (fetchDepth && fetchDepth > 0) { args.push(`--depth=${fetchDepth}`) } else if ( diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 48f20da28..0bcdab332 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -159,17 +159,17 @@ export async function getSource(settings: IGitSourceSettings): Promise { settings.ref, settings.commit ) - await git.fetch(refSpec) + await git.fetch(refSpec, settings.fetchDepth, settings.showProgress) // When all history is fetched, the ref we're interested in may have moved to a different // commit (push or force push). If so, fetch again with a targeted refspec. if (!(await refHelper.testRef(git, settings.ref, settings.commit))) { refSpec = refHelper.getRefSpec(settings.ref, settings.commit) - await git.fetch(refSpec) + await git.fetch(refSpec, settings.fetchDepth, settings.showProgress) } } else { const refSpec = refHelper.getRefSpec(settings.ref, settings.commit) - await git.fetch(refSpec, settings.fetchDepth) + await git.fetch(refSpec, settings.fetchDepth, settings.showProgress) } core.endGroup() diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 2da562266..24dd2bace 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -34,6 +34,11 @@ export interface IGitSourceSettings { */ fetchDepth: number + /** + * Indicates whether to use the --progress option when fetching + */ + showProgress: boolean + /** * Indicates whether to fetch LFS objects */ diff --git a/src/input-helper.ts b/src/input-helper.ts index 237b06aff..f446c5f9a 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -89,6 +89,11 @@ export async function getInputs(): Promise { } core.debug(`fetch depth = ${result.fetchDepth}`) + // Show fetch progress + result.showProgress = + (core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE' + core.debug(`show progress = ${result.showProgress}`) + // LFS result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE' core.debug(`lfs = ${result.lfs}`)