mirror of
https://code.forgejo.org/actions/checkout.git
synced 2026-03-09 14:35:48 +00:00
feat: override fetch-depth to 0 when reference-cache is active
When reference-cache is enabled, shallow fetches (fetch-depth > 0) are counterproductive because objects are served from the local cache. Shallow negotiation only adds network latency without saving bandwidth. If fetch-depth was not explicitly set by the user, it is automatically overridden to 0. If explicitly set, a warning is emitted explaining the performance impact. Signed-off-by: Michael Wyraz <mw@brick4u.de>
This commit is contained in:
parent
9ddd3f4b35
commit
ed69f3bbdd
6 changed files with 153 additions and 2 deletions
88
__test__/git-source-provider.test.ts
Normal file
88
__test__/git-source-provider.test.ts
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
import * as core from '@actions/core'
|
||||
import {adjustFetchDepthForCache} from '../src/git-source-provider'
|
||||
|
||||
// Mock @actions/core
|
||||
jest.mock('@actions/core')
|
||||
|
||||
describe('adjustFetchDepthForCache', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it('does nothing when referenceCache is not set', () => {
|
||||
const settings = {
|
||||
referenceCache: '',
|
||||
fetchDepth: 1,
|
||||
fetchDepthExplicit: false
|
||||
}
|
||||
adjustFetchDepthForCache(settings)
|
||||
expect(settings.fetchDepth).toBe(1)
|
||||
expect(core.warning).not.toHaveBeenCalled()
|
||||
expect(core.info).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('overrides fetchDepth to 0 when referenceCache is set and fetchDepth is default', () => {
|
||||
const settings = {
|
||||
referenceCache: '/cache/git-reference-cache',
|
||||
fetchDepth: 1,
|
||||
fetchDepthExplicit: false
|
||||
}
|
||||
adjustFetchDepthForCache(settings)
|
||||
expect(settings.fetchDepth).toBe(0)
|
||||
expect(core.info).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Overriding fetch-depth from 1 to 0')
|
||||
)
|
||||
expect(core.warning).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('warns but keeps fetchDepth when referenceCache is set and fetchDepth is explicit', () => {
|
||||
const settings = {
|
||||
referenceCache: '/cache/git-reference-cache',
|
||||
fetchDepth: 1,
|
||||
fetchDepthExplicit: true
|
||||
}
|
||||
adjustFetchDepthForCache(settings)
|
||||
expect(settings.fetchDepth).toBe(1)
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
expect.stringContaining("'fetch-depth: 1' is set with reference-cache enabled")
|
||||
)
|
||||
expect(core.info).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does nothing when referenceCache is set and fetchDepth is already 0 (explicit)', () => {
|
||||
const settings = {
|
||||
referenceCache: '/cache/git-reference-cache',
|
||||
fetchDepth: 0,
|
||||
fetchDepthExplicit: true
|
||||
}
|
||||
adjustFetchDepthForCache(settings)
|
||||
expect(settings.fetchDepth).toBe(0)
|
||||
expect(core.warning).not.toHaveBeenCalled()
|
||||
expect(core.info).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does nothing when referenceCache is set and fetchDepth is already 0 (default)', () => {
|
||||
const settings = {
|
||||
referenceCache: '/cache/git-reference-cache',
|
||||
fetchDepth: 0,
|
||||
fetchDepthExplicit: false
|
||||
}
|
||||
adjustFetchDepthForCache(settings)
|
||||
expect(settings.fetchDepth).toBe(0)
|
||||
expect(core.warning).not.toHaveBeenCalled()
|
||||
expect(core.info).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('warns with correct depth value when explicit fetchDepth is > 1', () => {
|
||||
const settings = {
|
||||
referenceCache: '/cache/git-reference-cache',
|
||||
fetchDepth: 42,
|
||||
fetchDepthExplicit: true
|
||||
}
|
||||
adjustFetchDepthForCache(settings)
|
||||
expect(settings.fetchDepth).toBe(42)
|
||||
expect(core.warning).toHaveBeenCalledWith(
|
||||
expect.stringContaining("'fetch-depth: 42' is set with reference-cache enabled")
|
||||
)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue