From 25e07a18d3878b6a06ed33a219b1a9e82198efc1 Mon Sep 17 00:00:00 2001 From: vvish Date: Thu, 19 Nov 2020 23:26:44 +0100 Subject: [PATCH] Added separate parameter for submodules fetch depth --- __test__/git-auth-helper.test.ts | 1 + __test__/input-helper.test.ts | 15 +++++++++++++++ dist/index.js | 8 +++++++- src/git-source-provider.ts | 2 +- src/git-source-settings.ts | 5 +++++ src/input-helper.ts | 9 +++++++++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 2b4830c..dd007e3 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -763,6 +763,7 @@ async function setup(testName: string): Promise { lfs: false, submodules: false, nestedSubmodules: false, + submodulesFetchDepth: 1, persistCredentials: true, ref: 'refs/heads/main', repositoryName: 'my-repo', diff --git a/__test__/input-helper.test.ts b/__test__/input-helper.test.ts index 920bc8e..509c4d7 100644 --- a/__test__/input-helper.test.ts +++ b/__test__/input-helper.test.ts @@ -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) + }) }) diff --git a/dist/index.js b/dist/index.js index e765cc2..08d3e1b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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}`); diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 42a12e0..06b9d39 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -180,7 +180,7 @@ export async function getSource(settings: IGitSourceSettings): Promise { core.startGroup('Fetching submodules') await git.submoduleSync(settings.nestedSubmodules) await git.submoduleUpdate( - settings.fetchDepth, + settings.submodulesFetchDepth, settings.nestedSubmodules ) await git.submoduleForeach( diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 2786222..9527365 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -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 */ diff --git a/src/input-helper.ts b/src/input-helper.ts index 4c05d6e..ca954b7 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -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}`)