Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added separate parameter for submodules fetch depth #392

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})
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}`)