Skip to content

Commit 3327cce

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 f095bcc commit 3327cce

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
@@ -801,6 +801,7 @@ async function setup(testName: string): Promise<void> {
801801
clean: true,
802802
commit: '',
803803
fetchDepth: 1,
804+
showProgress: true,
804805
lfs: false,
805806
submodules: false,
806807
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
@@ -615,13 +615,16 @@ class GitCommandManager {
615615
return output.exitCode === 0;
616616
});
617617
}
618-
fetch(refSpec, fetchDepth) {
618+
fetch(refSpec, fetchDepth, showProgress) {
619619
return __awaiter(this, void 0, void 0, function* () {
620620
const args = ['-c', 'protocol.version=2', 'fetch'];
621621
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
622622
args.push('--no-tags');
623623
}
624-
args.push('--prune', '--progress', '--no-recurse-submodules');
624+
args.push('--prune', '--no-recurse-submodules');
625+
if (showProgress) {
626+
args.push('--progress');
627+
}
625628
if (fetchDepth && fetchDepth > 0) {
626629
args.push(`--depth=${fetchDepth}`);
627630
}
@@ -1213,17 +1216,17 @@ function getSource(settings) {
12131216
if (settings.fetchDepth <= 0) {
12141217
// Fetch all branches and tags
12151218
let refSpec = refHelper.getRefSpecForAllHistory(settings.ref, settings.commit);
1216-
yield git.fetch(refSpec);
1219+
yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress);
12171220
// When all history is fetched, the ref we're interested in may have moved to a different
12181221
// commit (push or force push). If so, fetch again with a targeted refspec.
12191222
if (!(yield refHelper.testRef(git, settings.ref, settings.commit))) {
12201223
refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
1221-
yield git.fetch(refSpec);
1224+
yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress);
12221225
}
12231226
}
12241227
else {
12251228
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
1226-
yield git.fetch(refSpec, settings.fetchDepth);
1229+
yield git.fetch(refSpec, settings.fetchDepth, settings.showProgress);
12271230
}
12281231
core.endGroup();
12291232
// Checkout info
@@ -1679,6 +1682,10 @@ function getInputs() {
16791682
result.fetchDepth = 0;
16801683
}
16811684
core.debug(`fetch depth = ${result.fetchDepth}`);
1685+
// Show fetch progress
1686+
result.showProgress =
1687+
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE';
1688+
core.debug(`show progress = ${result.showProgress}`);
16821689
// LFS
16831690
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
16841691
core.debug(`lfs = ${result.lfs}`);

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>
@@ -202,13 +206,21 @@ class GitCommandManager {
202206
return output.exitCode === 0
203207
}
204208

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

211-
args.push('--prune', '--progress', '--no-recurse-submodules')
219+
args.push('--prune', '--no-recurse-submodules')
220+
if (showProgress) {
221+
args.push('--progress')
222+
}
223+
212224
if (fetchDepth && fetchDepth > 0) {
213225
args.push(`--depth=${fetchDepth}`)
214226
} 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)