Added separate parameter for submodules fetch depth

This commit is contained in:
vvish 2020-11-19 23:26:44 +01:00
parent 5a4ac9002d
commit 25e07a18d3
6 changed files with 38 additions and 2 deletions

View file

@ -763,6 +763,7 @@ async function setup(testName: string): Promise<void> {
lfs: false,
submodules: false,
nestedSubmodules: false,
submodulesFetchDepth: 1,
persistCredentials: true,
ref: 'refs/heads/main',
repositoryName: 'my-repo',

View file

@ -75,6 +75,7 @@ describe('input-helper tests', () => {
expect(settings.commit).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.fetchDepth).toBe(1)
expect(settings.submodulesFetchDepth).toBe(1)
expect(settings.lfs).toBe(false)
expect(settings.ref).toBe('refs/heads/some-ref')
expect(settings.repositoryName).toBe('some-repo')
@ -123,4 +124,18 @@ describe('input-helper tests', () => {
expect(settings.ref).toBe('refs/heads/some-other-ref')
expect(settings.commit).toBeFalsy()
})
it('sets submodulesFetchDepth independently from fetchDepth', () => {
inputs['fetch-depth'] = '10'
inputs['submodules-fetch-depth'] = '20'
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings.submodulesFetchDepth).toBe(20)
})
it('sets submodulesFetchDepth equal to fetchDepth by default', () => {
inputs['fetch-depth'] = '10'
const settings: IGitSourceSettings = inputHelper.getInputs()
expect(settings.submodulesFetchDepth).toBe(10)
})
})

8
dist/index.js vendored
View file

@ -6255,7 +6255,7 @@ function getSource(settings) {
// Checkout submodules
core.startGroup('Fetching submodules');
yield git.submoduleSync(settings.nestedSubmodules);
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
yield git.submoduleUpdate(settings.submodulesFetchDepth, settings.nestedSubmodules);
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
core.endGroup();
// Persist credentials
@ -14572,6 +14572,12 @@ function getInputs() {
result.fetchDepth = 0;
}
core.debug(`fetch depth = ${result.fetchDepth}`);
// Submodules fetch depth
result.submodulesFetchDepth = Math.floor(Number(core.getInput('submodules-fetch-depth') || '-1'));
if (isNaN(result.submodulesFetchDepth) || result.submodulesFetchDepth < 0) {
result.submodulesFetchDepth = result.fetchDepth;
}
core.debug(`submodules fetch depth = ${result.submodulesFetchDepth}`);
// LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
core.debug(`lfs = ${result.lfs}`);

View file

@ -180,7 +180,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
core.startGroup('Fetching submodules')
await git.submoduleSync(settings.nestedSubmodules)
await git.submoduleUpdate(
settings.fetchDepth,
settings.submodulesFetchDepth,
settings.nestedSubmodules
)
await git.submoduleForeach(

View file

@ -49,6 +49,11 @@ export interface IGitSourceSettings {
*/
nestedSubmodules: boolean
/**
* The fetch depth for submodules
*/
submodulesFetchDepth: number
/**
* The auth token to use when fetching the repository
*/

View file

@ -88,6 +88,15 @@ export function getInputs(): IGitSourceSettings {
}
core.debug(`fetch depth = ${result.fetchDepth}`)
// Submodules fetch depth
result.submodulesFetchDepth = Math.floor(
Number(core.getInput('submodules-fetch-depth') || '-1')
)
if (isNaN(result.submodulesFetchDepth) || result.submodulesFetchDepth < 0) {
result.submodulesFetchDepth = result.fetchDepth
}
core.debug(`submodules fetch depth = ${result.submodulesFetchDepth}`)
// LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
core.debug(`lfs = ${result.lfs}`)