Skip to content

Commit

Permalink
Added separate parameter for submodules fetch depth
Browse files Browse the repository at this point in the history
  • Loading branch information
vvish committed Nov 22, 2020
1 parent 5a4ac90 commit abd1df2
Showing 7 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
@@ -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',
15 changes: 15 additions & 0 deletions __test__/input-helper.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -68,6 +68,8 @@ inputs:
When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are
converted to HTTPS.
default: false
submodules-fetch-depth:
description: 'Number of commits to fetch for submodules. If not present defaults to fetch-depth'
runs:
using: node12
main: dist/index.js
8 changes: 7 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
@@ -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}`);
2 changes: 1 addition & 1 deletion src/git-source-provider.ts
Original file line number Diff line number Diff line change
@@ -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(
5 changes: 5 additions & 0 deletions src/git-source-settings.ts
Original file line number Diff line number Diff line change
@@ -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
*/
9 changes: 9 additions & 0 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
@@ -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}`)

0 comments on commit abd1df2

Please sign in to comment.