Skip to content

Commit 8b5e8b7

Browse files
authored
Support fetching without the --progress option (#1067)
Setting the `show-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. Adding the --quiet flag doesn't make a lot of difference once the --progress flag is removed, and actually I think using --quiet would suppress some other more useful output that would be better left visible. Signed-off-by: Simon Baird <[email protected]>
1 parent 97a652b commit 8b5e8b7

10 files changed

+155
-7
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ When Git 2.18 or higher is not in your PATH, falls back to the REST API to downl
9191
# Default: false
9292
fetch-tags: ''
9393

94+
# Whether to show progress status output when fetching.
95+
# Default: true
96+
show-progress: ''
97+
9498
# Whether to download Git-LFS files
9599
# Default: false
96100
lfs: ''

__test__/git-auth-helper.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ async function setup(testName: string): Promise<void> {
806806
sparseCheckoutConeMode: true,
807807
fetchDepth: 1,
808808
fetchTags: false,
809+
showProgress: true,
809810
lfs: false,
810811
submodules: false,
811812
nestedSubmodules: false,

__test__/git-command-manager.test.ts

+116-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ describe('Test fetchDepth and fetchTags options', () => {
135135
'protocol.version=2',
136136
'fetch',
137137
'--prune',
138-
'--progress',
139138
'--no-recurse-submodules',
140139
'--filter=filterValue',
141140
'origin',
@@ -174,7 +173,6 @@ describe('Test fetchDepth and fetchTags options', () => {
174173
'fetch',
175174
'--no-tags',
176175
'--prune',
177-
'--progress',
178176
'--no-recurse-submodules',
179177
'--filter=filterValue',
180178
'origin',
@@ -213,7 +211,6 @@ describe('Test fetchDepth and fetchTags options', () => {
213211
'fetch',
214212
'--no-tags',
215213
'--prune',
216-
'--progress',
217214
'--no-recurse-submodules',
218215
'--filter=filterValue',
219216
'--depth=1',
@@ -252,7 +249,6 @@ describe('Test fetchDepth and fetchTags options', () => {
252249
'protocol.version=2',
253250
'fetch',
254251
'--prune',
255-
'--progress',
256252
'--no-recurse-submodules',
257253
'--filter=filterValue',
258254
'--depth=1',
@@ -263,4 +259,120 @@ describe('Test fetchDepth and fetchTags options', () => {
263259
expect.any(Object)
264260
)
265261
})
262+
263+
it('should call execGit with the correct arguments when showProgress is true', async () => {
264+
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
265+
266+
const workingDirectory = 'test'
267+
const lfs = false
268+
const doSparseCheckout = false
269+
git = await commandManager.createCommandManager(
270+
workingDirectory,
271+
lfs,
272+
doSparseCheckout
273+
)
274+
const refSpec = ['refspec1', 'refspec2']
275+
const options = {
276+
filter: 'filterValue',
277+
showProgress: true
278+
}
279+
280+
await git.fetch(refSpec, options)
281+
282+
expect(mockExec).toHaveBeenCalledWith(
283+
expect.any(String),
284+
[
285+
'-c',
286+
'protocol.version=2',
287+
'fetch',
288+
'--no-tags',
289+
'--prune',
290+
'--no-recurse-submodules',
291+
'--progress',
292+
'--filter=filterValue',
293+
'origin',
294+
'refspec1',
295+
'refspec2'
296+
],
297+
expect.any(Object)
298+
)
299+
})
300+
301+
it('should call execGit with the correct arguments when fetchDepth is 42 and showProgress is true', async () => {
302+
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
303+
304+
const workingDirectory = 'test'
305+
const lfs = false
306+
const doSparseCheckout = false
307+
git = await commandManager.createCommandManager(
308+
workingDirectory,
309+
lfs,
310+
doSparseCheckout
311+
)
312+
const refSpec = ['refspec1', 'refspec2']
313+
const options = {
314+
filter: 'filterValue',
315+
fetchDepth: 42,
316+
showProgress: true
317+
}
318+
319+
await git.fetch(refSpec, options)
320+
321+
expect(mockExec).toHaveBeenCalledWith(
322+
expect.any(String),
323+
[
324+
'-c',
325+
'protocol.version=2',
326+
'fetch',
327+
'--no-tags',
328+
'--prune',
329+
'--no-recurse-submodules',
330+
'--progress',
331+
'--filter=filterValue',
332+
'--depth=42',
333+
'origin',
334+
'refspec1',
335+
'refspec2'
336+
],
337+
expect.any(Object)
338+
)
339+
})
340+
341+
it('should call execGit with the correct arguments when fetchTags is true and showProgress is true', async () => {
342+
jest.spyOn(exec, 'exec').mockImplementation(mockExec)
343+
344+
const workingDirectory = 'test'
345+
const lfs = false
346+
const doSparseCheckout = false
347+
git = await commandManager.createCommandManager(
348+
workingDirectory,
349+
lfs,
350+
doSparseCheckout
351+
)
352+
const refSpec = ['refspec1', 'refspec2']
353+
const options = {
354+
filter: 'filterValue',
355+
fetchTags: true,
356+
showProgress: true
357+
}
358+
359+
await git.fetch(refSpec, options)
360+
361+
expect(mockExec).toHaveBeenCalledWith(
362+
expect.any(String),
363+
[
364+
'-c',
365+
'protocol.version=2',
366+
'fetch',
367+
'--prune',
368+
'--no-recurse-submodules',
369+
'--progress',
370+
'--filter=filterValue',
371+
'origin',
372+
'refspec1',
373+
'refspec2'
374+
],
375+
expect.any(Object)
376+
)
377+
})
266378
})

__test__/input-helper.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('input-helper tests', () => {
8383
expect(settings.sparseCheckoutConeMode).toBe(true)
8484
expect(settings.fetchDepth).toBe(1)
8585
expect(settings.fetchTags).toBe(false)
86+
expect(settings.showProgress).toBe(true)
8687
expect(settings.lfs).toBe(false)
8788
expect(settings.ref).toBe('refs/heads/some-ref')
8889
expect(settings.repositoryName).toBe('some-repo')

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ inputs:
6868
fetch-tags:
6969
description: 'Whether to fetch tags, even if fetch-depth > 0.'
7070
default: false
71+
show-progress:
72+
description: 'Whether to show progress status output when fetching.'
73+
default: true
7174
lfs:
7275
description: 'Whether to download Git-LFS files'
7376
default: false

dist/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,10 @@ class GitCommandManager {
640640
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !options.fetchTags) {
641641
args.push('--no-tags');
642642
}
643-
args.push('--prune', '--progress', '--no-recurse-submodules');
643+
args.push('--prune', '--no-recurse-submodules');
644+
if (options.showProgress) {
645+
args.push('--progress');
646+
}
644647
if (options.filter) {
645648
args.push(`--filter=${options.filter}`);
646649
}
@@ -1739,6 +1742,10 @@ function getInputs() {
17391742
result.fetchTags =
17401743
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE';
17411744
core.debug(`fetch tags = ${result.fetchTags}`);
1745+
// Show fetch progress
1746+
result.showProgress =
1747+
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE';
1748+
core.debug(`show progress = ${result.showProgress}`);
17421749
// LFS
17431750
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
17441751
core.debug(`lfs = ${result.lfs}`);

src/git-command-manager.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface IGitCommandManager {
3434
filter?: string
3535
fetchDepth?: number
3636
fetchTags?: boolean
37+
showProgress?: boolean
3738
}
3839
): Promise<void>
3940
getDefaultBranch(repositoryUrl: string): Promise<string>
@@ -241,14 +242,22 @@ class GitCommandManager {
241242

242243
async fetch(
243244
refSpec: string[],
244-
options: {filter?: string; fetchDepth?: number; fetchTags?: boolean}
245+
options: {
246+
filter?: string
247+
fetchDepth?: number
248+
fetchTags?: boolean
249+
showProgress?: boolean
250+
}
245251
): Promise<void> {
246252
const args = ['-c', 'protocol.version=2', 'fetch']
247253
if (!refSpec.some(x => x === refHelper.tagsRefSpec) && !options.fetchTags) {
248254
args.push('--no-tags')
249255
}
250256

251-
args.push('--prune', '--progress', '--no-recurse-submodules')
257+
args.push('--prune', '--no-recurse-submodules')
258+
if (options.showProgress) {
259+
args.push('--progress')
260+
}
252261

253262
if (options.filter) {
254263
args.push(`--filter=${options.filter}`)

src/git-source-provider.ts

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
157157
filter?: string
158158
fetchDepth?: number
159159
fetchTags?: boolean
160+
showProgress?: boolean
160161
} = {}
161162
if (settings.sparseCheckout) fetchOptions.filter = 'blob:none'
162163
if (settings.fetchDepth <= 0) {

src/git-source-settings.ts

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export interface IGitSourceSettings {
4949
*/
5050
fetchTags: boolean
5151

52+
/**
53+
* Indicates whether to use the --progress option when fetching
54+
*/
55+
showProgress: boolean
56+
5257
/**
5358
* Indicates whether to fetch LFS objects
5459
*/

src/input-helper.ts

+5
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export async function getInputs(): Promise<IGitSourceSettings> {
105105
(core.getInput('fetch-tags') || 'false').toUpperCase() === 'TRUE'
106106
core.debug(`fetch tags = ${result.fetchTags}`)
107107

108+
// Show fetch progress
109+
result.showProgress =
110+
(core.getInput('show-progress') || 'true').toUpperCase() === 'TRUE'
111+
core.debug(`show progress = ${result.showProgress}`)
112+
108113
// LFS
109114
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
110115
core.debug(`lfs = ${result.lfs}`)

0 commit comments

Comments
 (0)