Skip to content

Commit 87596e0

Browse files
committed
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.
1 parent ac59398 commit 87596e0

File tree

8 files changed

+48
-11
lines changed

8 files changed

+48
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
7878
# Default: 1
7979
fetch-depth: ''
8080

81+
# Whether to show progress status output when fetching.
82+
# Default: true
83+
show-progress: ''
84+
8185
# Whether to download Git-LFS files
8286
# Default: false
8387
lfs: ''

__test__/git-auth-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ async function setup(testName: string): Promise<void> {
798798
clean: true,
799799
commit: '',
800800
fetchDepth: 1,
801+
showProgress: true,
801802
lfs: false,
802803
submodules: false,
803804
nestedSubmodules: false,

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ inputs:
5656
fetch-depth:
5757
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
5858
default: 1
59+
show-progress:
60+
description: 'Whether to show progress status output when fetching.'
61+
default: true
5962
lfs:
6063
description: 'Whether to download Git-LFS files'
6164
default: false

dist/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7533,13 +7533,16 @@ class GitCommandManager {
75337533
return output.exitCode === 0;
75347534
});
75357535
}
7536-
fetch(refSpec, fetchDepth) {
7536+
fetch(refSpec, fetchDepth, showProgress) {
75377537
return __awaiter(this, void 0, void 0, function* () {
75387538
const args = ['-c', 'protocol.version=2', 'fetch'];
75397539
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
75407540
args.push('--no-tags');
75417541
}
7542-
args.push('--prune', '--progress', '--no-recurse-submodules');
7542+
args.push('--prune', '--no-recurse-submodules');
7543+
if (showProgress) {
7544+
args.push('--progress');
7545+
}
75437546
if (fetchDepth && fetchDepth > 0) {
75447547
args.push(`--depth=${fetchDepth}`);
75457548
}
@@ -18521,6 +18524,10 @@ function getInputs() {
1852118524
result.fetchDepth = 0;
1852218525
}
1852318526
core.debug(`fetch depth = ${result.fetchDepth}`);
18527+
// Show fetch progress
18528+
result.showProgress =
18529+
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE';
18530+
core.debug(`show progress = ${result.showProgress}`);
1852418531
// LFS
1852518532
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1852618533
core.debug(`lfs = ${result.lfs}`);
@@ -31971,17 +31978,17 @@ function getSource(settings) {
3197131978
if (settings.fetchDepth <= 0) {
3197231979
// Fetch all branches and tags
3197331980
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
31974-
yield git.fetch(refSpec);
31981+
yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress);
3197531982
// When all history is fetched, the ref we're interested in may have moved to a different
3197631983
// commit (push or force push). If so, fetch again with a targeted refspec.
3197731984
if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) {
3197831985
refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
31979-
yield git.fetch(refSpec);
31986+
yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress);
3198031987
}
3198131988
}
3198231989
else {
3198331990
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
31984-
yield git.fetch(refSpec, settings.fetchDepth);
31991+
yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress);
3198531992
}
3198631993
core.endGroup();
3198731994
// Checkout info

src/git-command-manager.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export interface IGitCommandManager {
2525
add?: boolean
2626
): Promise<void>
2727
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
28-
fetch(refSpec: string[], fetchDepth?: number): Promise<void>
28+
fetch(
29+
refSpec: string[],
30+
fetchDepth: number,
31+
showProgress: boolean
32+
): Promise<void>
2933
getDefaultBranch(repositoryUrl: string): Promise<string>
3034
getWorkingDirectory(): string
3135
init(): Promise<void>
@@ -201,13 +205,21 @@ class GitCommandManager {
201205
return output.exitCode === 0
202206
}
203207

204-
async fetch(refSpec: string[], fetchDepth?: number): Promise<void> {
208+
async fetch(
209+
refSpec: string[],
210+
fetchDepth: number,
211+
showProgress: boolean
212+
): Promise<void> {
205213
const args = ['-c', 'protocol.version=2', 'fetch']
206214
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
207215
args.push('--no-tags')
208216
}
209217

210-
args.push('--prune', '--progress', '--no-recurse-submodules')
218+
args.push('--prune', '--no-recurse-submodules')
219+
if (showProgress) {
220+
args.push('--progress')
221+
}
222+
211223
if (fetchDepth && fetchDepth > 0) {
212224
args.push(`--depth=${fetchDepth}`)
213225
} else if (

src/git-source-provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,17 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
159159
settings.ref,
160160
settings.commit
161161
)
162-
await git.fetch(refSpec)
162+
await git.fetch(refSpec, settings.fetchDepth, settings.showProgress)
163163

164164
// When all history is fetched, the ref we're interested in may have moved to a different
165165
// commit (push or force push). If so, fetch again with a targeted refspec.
166166
if (!(await refHelper.testRef(git, settings.ref, settings.commit))) {
167167
refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
168-
await git.fetch(refSpec)
168+
await git.fetch(refSpec, settings.fetchDepth, settings.showProgress)
169169
}
170170
} else {
171171
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
172-
await git.fetch(refSpec, settings.fetchDepth)
172+
await git.fetch(refSpec, settings.fetchDepth, settings.showProgress)
173173
}
174174
core.endGroup()
175175

src/git-source-settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export interface IGitSourceSettings {
3434
*/
3535
fetchDepth: number
3636

37+
/**
38+
* Indicates whether to use the --progress option when fetching
39+
*/
40+
showProgress: boolean
41+
3742
/**
3843
* Indicates whether to fetch LFS objects
3944
*/

src/input-helper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ export async function getInputs(): Promise<IGitSourceSettings> {
8989
}
9090
core.debug(`fetch depth = ${result.fetchDepth}`)
9191

92+
// Show fetch progress
93+
result.showProgress =
94+
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE'
95+
core.debug(`show progress = ${result.showProgress}`)
96+
9297
// LFS
9398
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
9499
core.debug(`lfs = ${result.lfs}`)

0 commit comments

Comments
 (0)