Add a quiet input to suppress git output

Adds a `quiet` input (default: false) that passes `--quiet` to the git
commands that fetch and check out the repository: `fetch`, `checkout`,
`checkout --detach`, and `submodule update`.

With `fetch-depth: 0` the refspec covers every branch and tag, so git
prints a `From <url>` line plus one `* [new branch]` / `* [new tag]` line
per ref. On a ref-heavy repository that summary is the bulk of the
checkout log, and `show-progress: false` does not remove it -- that input
only ever controlled `--progress`.

`--quiet` and `--progress` drive different output and compose rather than
conflict: `--progress` forces the transfer/update meter, while `--quiet`
drops the ref summary and other informational messages. `checkout` keeps
its `--progress` when quiet, so a slow checkout still reports progress.

`git lfs fetch` has no `--quiet` flag, so LFS output is unchanged.

Fixes #2409
This commit is contained in:
Mostafa Zaher 2026-09-01 11:38:32 +03:00
parent f548e57e54
commit 81a936fd3c
10 changed files with 299 additions and 14 deletions

View file

@ -1180,6 +1180,7 @@ async function setup(testName: string): Promise<void> {
fetchDepth: 1,
fetchTags: false,
showProgress: true,
quiet: false,
lfs: false,
submodules: false,
nestedSubmodules: false,

View file

@ -572,3 +572,209 @@ describe('git user-agent with orchestration ID', () => {
)
})
})
describe('Test quiet option', () => {
beforeEach(async () => {
mockFileExistsSync.mockReset()
mockDirectoryExistsSync.mockReset()
mockExec.mockImplementation((path: any, args: any, options: any) => {
if (args.includes('version')) {
options.listeners.stdout(Buffer.from('2.18'))
}
return 0
})
})
afterEach(() => {
jest.clearAllMocks()
})
async function createManager(quiet?: boolean): Promise<IGitCommandManager> {
const workingDirectory = 'test'
const lfs = false
const doSparseCheckout = false
return await commandManager.createCommandManager(
workingDirectory,
lfs,
doSparseCheckout,
quiet
)
}
it('should pass --quiet to fetch when quiet is true', async () => {
git = await createManager(true)
await git.fetch(['refspec1'], {fetchDepth: 0})
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'-c',
'protocol.version=2',
'fetch',
'--no-tags',
'--prune',
'--no-recurse-submodules',
'--quiet',
'origin',
'refspec1'
],
expect.any(Object)
)
})
it('should pass both --quiet and --progress to fetch when both are requested', async () => {
// The two flags drive different output and compose: --progress forces the
// transfer meter, --quiet drops the per-ref summary.
git = await createManager(true)
await git.fetch(['refspec1'], {fetchDepth: 0, showProgress: true})
const args = mockExec.mock.calls.at(-1)?.[1] as string[]
expect(args).toContain('--quiet')
expect(args).toContain('--progress')
})
it('should not pass --quiet to fetch when quiet is false', async () => {
git = await createManager(false)
await git.fetch(['refspec1'], {fetchDepth: 0})
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'-c',
'protocol.version=2',
'fetch',
'--no-tags',
'--prune',
'--no-recurse-submodules',
'origin',
'refspec1'
],
expect.any(Object)
)
})
it('should default to not quiet when the option is omitted', async () => {
git = await createManager()
await git.fetch(['refspec1'], {fetchDepth: 0, showProgress: true})
const args = mockExec.mock.calls.at(-1)?.[1] as string[]
expect(args).toContain('--progress')
expect(args).not.toContain('--quiet')
})
it('should checkout with --quiet alongside --progress when quiet is true', async () => {
git = await createManager(true)
await git.checkout('refs/heads/main', '')
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
['checkout', '--quiet', '--progress', '--force', 'refs/heads/main'],
expect.any(Object)
)
})
it('should checkout a start point with --quiet when quiet is true', async () => {
git = await createManager(true)
await git.checkout('refs/heads/main', 'refs/remotes/origin/main')
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'checkout',
'--quiet',
'--progress',
'--force',
'-B',
'refs/heads/main',
'refs/remotes/origin/main'
],
expect.any(Object)
)
})
it('should checkout with --progress when quiet is false', async () => {
git = await createManager(false)
await git.checkout('refs/heads/main', '')
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
['checkout', '--progress', '--force', 'refs/heads/main'],
expect.any(Object)
)
})
it('should pass --quiet to checkout --detach when quiet is true', async () => {
git = await createManager(true)
await git.checkoutDetach()
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
['checkout', '--detach', '--quiet'],
expect.any(Object)
)
})
it('should not pass --quiet to checkout --detach when quiet is false', async () => {
git = await createManager(false)
await git.checkoutDetach()
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
['checkout', '--detach'],
expect.any(Object)
)
})
it('should pass --quiet to submodule update when quiet is true', async () => {
git = await createManager(true)
await git.submoduleUpdate(1, true)
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'-c',
'protocol.version=2',
'submodule',
'update',
'--init',
'--force',
'--quiet',
'--depth=1',
'--recursive'
],
expect.any(Object)
)
})
it('should not pass --quiet to submodule update when quiet is false', async () => {
git = await createManager(false)
await git.submoduleUpdate(1, true)
expect(mockExec).toHaveBeenCalledWith(
expect.any(String),
[
'-c',
'protocol.version=2',
'submodule',
'update',
'--init',
'--force',
'--depth=1',
'--recursive'
],
expect.any(Object)
)
})
})

View file

@ -119,6 +119,7 @@ describe('input-helper tests', () => {
expect(settings.fetchDepth).toBe(1)
expect(settings.fetchTags).toBe(false)
expect(settings.showProgress).toBe(true)
expect(settings.quiet).toBe(false)
expect(settings.lfs).toBe(false)
expect(settings.ref).toBe('refs/heads/some-ref')
expect(settings.repositoryName).toBe('some-repo')
@ -128,6 +129,12 @@ describe('input-helper tests', () => {
expect(settings.allowUnsafePrCheckout).toBe(false)
})
it('sets quiet', async () => {
inputs.quiet = 'true'
const settings: IGitSourceSettings = await inputHelper.getInputs()
expect(settings.quiet).toBe(true)
})
it('qualifies ref', async () => {
let originalRef = mockGithubContext.ref
try {