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, lfs: false,
submodules: false, submodules: false,
nestedSubmodules: false, nestedSubmodules: false,
submodulesFetchDepth: 1,
persistCredentials: true, persistCredentials: true,
ref: 'refs/heads/main', ref: 'refs/heads/main',
repositoryName: 'my-repo', repositoryName: 'my-repo',

View File

@ -75,6 +75,7 @@ describe('input-helper tests', () => {
expect(settings.commit).toBeTruthy() expect(settings.commit).toBeTruthy()
expect(settings.commit).toBe('1234567890123456789012345678901234567890') expect(settings.commit).toBe('1234567890123456789012345678901234567890')
expect(settings.fetchDepth).toBe(1) expect(settings.fetchDepth).toBe(1)
expect(settings.submodulesFetchDepth).toBe(1)
expect(settings.lfs).toBe(false) expect(settings.lfs).toBe(false)
expect(settings.ref).toBe('refs/heads/some-ref') expect(settings.ref).toBe('refs/heads/some-ref')
expect(settings.repositoryName).toBe('some-repo') 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.ref).toBe('refs/heads/some-other-ref')
expect(settings.commit).toBeFalsy() 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 // Checkout submodules
core.startGroup('Fetching submodules'); core.startGroup('Fetching submodules');
yield git.submoduleSync(settings.nestedSubmodules); 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); yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
core.endGroup(); core.endGroup();
// Persist credentials // Persist credentials
@ -14572,6 +14572,12 @@ function getInputs() {
result.fetchDepth = 0; result.fetchDepth = 0;
} }
core.debug(`fetch depth = ${result.fetchDepth}`); 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 // LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'; result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
core.debug(`lfs = ${result.lfs}`); core.debug(`lfs = ${result.lfs}`);

View File

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

View File

@ -49,6 +49,11 @@ export interface IGitSourceSettings {
*/ */
nestedSubmodules: boolean nestedSubmodules: boolean
/**
* The fetch depth for submodules
*/
submodulesFetchDepth: number
/** /**
* The auth token to use when fetching the repository * 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}`) 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 // LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE' result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
core.debug(`lfs = ${result.lfs}`) core.debug(`lfs = ${result.lfs}`)