Skip to content

Commit abd1df2

Browse files
committed
Added separate parameter for submodules fetch depth
1 parent 5a4ac90 commit abd1df2

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

__test__/git-auth-helper.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ async function setup(testName: string): Promise<void> {
763763
lfs: false,
764764
submodules: false,
765765
nestedSubmodules: false,
766+
submodulesFetchDepth: 1,
766767
persistCredentials: true,
767768
ref: 'refs/heads/main',
768769
repositoryName: 'my-repo',

__test__/input-helper.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('input-helper tests', () => {
7575
expect(settings.commit).toBeTruthy()
7676
expect(settings.commit).toBe('1234567890123456789012345678901234567890')
7777
expect(settings.fetchDepth).toBe(1)
78+
expect(settings.submodulesFetchDepth).toBe(1)
7879
expect(settings.lfs).toBe(false)
7980
expect(settings.ref).toBe('refs/heads/some-ref')
8081
expect(settings.repositoryName).toBe('some-repo')
@@ -123,4 +124,18 @@ describe('input-helper tests', () => {
123124
expect(settings.ref).toBe('refs/heads/some-other-ref')
124125
expect(settings.commit).toBeFalsy()
125126
})
127+
128+
it('sets submodulesFetchDepth independently from fetchDepth', () => {
129+
inputs['fetch-depth'] = '10'
130+
inputs['submodules-fetch-depth'] = '20'
131+
132+
const settings: IGitSourceSettings = inputHelper.getInputs()
133+
expect(settings.submodulesFetchDepth).toBe(20)
134+
})
135+
136+
it('sets submodulesFetchDepth equal to fetchDepth by default', () => {
137+
inputs['fetch-depth'] = '10'
138+
const settings: IGitSourceSettings = inputHelper.getInputs()
139+
expect(settings.submodulesFetchDepth).toBe(10)
140+
})
126141
})

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ inputs:
6868
When the `ssh-key` input is not provided, SSH URLs beginning with `git@github.com:` are
6969
converted to HTTPS.
7070
default: false
71+
submodules-fetch-depth:
72+
description: 'Number of commits to fetch for submodules. If not present defaults to fetch-depth'
7173
runs:
7274
using: node12
7375
main: dist/index.js

dist/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6255,7 +6255,7 @@ function getSource(settings) {
62556255
// Checkout submodules
62566256
core.startGroup('Fetching submodules');
62576257
yield git.submoduleSync(settings.nestedSubmodules);
6258-
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
6258+
yield git.submoduleUpdate(settings.submodulesFetchDepth, settings.nestedSubmodules);
62596259
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
62606260
core.endGroup();
62616261
// Persist credentials
@@ -14572,6 +14572,12 @@ function getInputs() {
1457214572
result.fetchDepth = 0;
1457314573
}
1457414574
core.debug(`fetch depth = ${result.fetchDepth}`);
14575+
// Submodules fetch depth
14576+
result.submodulesFetchDepth = Math.floor(Number(core.getInput('submodules-fetch-depth') || '-1'));
14577+
if (isNaN(result.submodulesFetchDepth) || result.submodulesFetchDepth < 0) {
14578+
result.submodulesFetchDepth = result.fetchDepth;
14579+
}
14580+
core.debug(`submodules fetch depth = ${result.submodulesFetchDepth}`);
1457514581
// LFS
1457614582
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1457714583
core.debug(`lfs = ${result.lfs}`);

src/git-source-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
180180
core.startGroup('Fetching submodules')
181181
await git.submoduleSync(settings.nestedSubmodules)
182182
await git.submoduleUpdate(
183-
settings.fetchDepth,
183+
settings.submodulesFetchDepth,
184184
settings.nestedSubmodules
185185
)
186186
await git.submoduleForeach(

src/git-source-settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export interface IGitSourceSettings {
4949
*/
5050
nestedSubmodules: boolean
5151

52+
/**
53+
* The fetch depth for submodules
54+
*/
55+
submodulesFetchDepth: number
56+
5257
/**
5358
* The auth token to use when fetching the repository
5459
*/

src/input-helper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ export function getInputs(): IGitSourceSettings {
8888
}
8989
core.debug(`fetch depth = ${result.fetchDepth}`)
9090

91+
// Submodules fetch depth
92+
result.submodulesFetchDepth = Math.floor(
93+
Number(core.getInput('submodules-fetch-depth') || '-1')
94+
)
95+
if (isNaN(result.submodulesFetchDepth) || result.submodulesFetchDepth < 0) {
96+
result.submodulesFetchDepth = result.fetchDepth
97+
}
98+
core.debug(`submodules fetch depth = ${result.submodulesFetchDepth}`)
99+
91100
// LFS
92101
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
93102
core.debug(`lfs = ${result.lfs}`)

0 commit comments

Comments
 (0)