Skip to content

Commit 7618b1f

Browse files
committedAug 28, 2024
Simplified the submoduleDirectories
1 parent b6625bb commit 7618b1f

8 files changed

+31
-61
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
116116
# Default: false
117117
submodules: ''
118118

119-
# A list of submodules to use when `submodules` is `true`.
119+
# A list of submodules to checkout.
120120
# Default: null
121121
submodule-directories: ''
122122

‎__test__/git-auth-helper.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ async function setup(testName: string): Promise<void> {
813813
lfs: false,
814814
submodules: false,
815815
nestedSubmodules: false,
816-
submoduleDirectories: null,
816+
submoduleDirectories: [],
817817
persistCredentials: true,
818818
ref: 'refs/heads/main',
819819
repositoryName: 'my-repo',

‎__test__/input-helper.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe('input-helper tests', () => {
9494
expect(settings.showProgress).toBe(true)
9595
expect(settings.lfs).toBe(false)
9696
expect(settings.ref).toBe('refs/heads/some-ref')
97-
expect(settings.submoduleDirectories).toBe(null)
97+
expect(settings.submoduleDirectories).toStrictEqual([])
9898
expect(settings.repositoryName).toBe('some-repo')
9999
expect(settings.repositoryOwner).toBe('some-owner')
100100
expect(settings.repositoryPath).toBe(gitHubWorkspace)

‎action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ inputs:
9494
default: false
9595
submodule-directories:
9696
description: >
97-
A list of submodules to use when `submodules` is `true`.
97+
A list of submodules to checkout.
9898
default: null
9999
set-safe-directory:
100100
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`

‎dist/index.js

+8-26
Original file line numberDiff line numberDiff line change
@@ -797,30 +797,15 @@ class GitCommandManager {
797797
}
798798
submoduleUpdate(fetchDepth, recursive, submoduleDirectories) {
799799
return __awaiter(this, void 0, void 0, function* () {
800-
if (submoduleDirectories) {
801-
for (const submodule of submoduleDirectories) {
802-
const args = ['-c', 'protocol.version=2'];
803-
args.push('submodule', 'update', '--init', '--force', submodule);
804-
if (fetchDepth > 0) {
805-
args.push(`--depth=${fetchDepth}`);
806-
}
807-
if (recursive) {
808-
args.push('--recursive');
809-
}
810-
yield this.execGit(args);
811-
}
800+
const args = ['-c', 'protocol.version=2'];
801+
args.push('submodule', 'update', '--init', '--force', ...submoduleDirectories);
802+
if (fetchDepth > 0) {
803+
args.push(`--depth=${fetchDepth}`);
812804
}
813-
else {
814-
const args = ['-c', 'protocol.version=2'];
815-
args.push('submodule', 'update', '--init', '--force');
816-
if (fetchDepth > 0) {
817-
args.push(`--depth=${fetchDepth}`);
818-
}
819-
if (recursive) {
820-
args.push('--recursive');
821-
}
822-
yield this.execGit(args);
805+
if (recursive) {
806+
args.push('--recursive');
823807
}
808+
yield this.execGit(args);
824809
});
825810
}
826811
submoduleStatus() {
@@ -1820,7 +1805,7 @@ function getInputs() {
18201805
// Submodules
18211806
result.submodules = false;
18221807
result.nestedSubmodules = false;
1823-
result.submoduleDirectories = null;
1808+
result.submoduleDirectories = [];
18241809
const submodulesString = (core.getInput('submodules') || '').toUpperCase();
18251810
if (submodulesString == 'RECURSIVE') {
18261811
result.submodules = true;
@@ -1835,9 +1820,6 @@ function getInputs() {
18351820
if (!result.submodules)
18361821
result.submodules = true;
18371822
}
1838-
else {
1839-
result.submoduleDirectories = null;
1840-
}
18411823
core.debug(`submodules = ${result.submodules}`);
18421824
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
18431825
core.debug(`submodule directories = ${result.submoduleDirectories}`);

‎src/git-command-manager.ts

+17-27
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export interface IGitCommandManager {
5757
submoduleUpdate(
5858
fetchDepth: number,
5959
recursive: boolean,
60-
submoduleDirectories: string[] | null
60+
submoduleDirectories: string[]
6161
): Promise<void>
6262
submoduleStatus(): Promise<boolean>
6363
tagExists(pattern: string): Promise<boolean>
@@ -416,35 +416,25 @@ class GitCommandManager {
416416
async submoduleUpdate(
417417
fetchDepth: number,
418418
recursive: boolean,
419-
submoduleDirectories: string[] | null
419+
submoduleDirectories: string[]
420420
): Promise<void> {
421-
if (submoduleDirectories) {
422-
for (const submodule of submoduleDirectories) {
423-
const args = ['-c', 'protocol.version=2']
424-
args.push('submodule', 'update', '--init', '--force', submodule)
425-
if (fetchDepth > 0) {
426-
args.push(`--depth=${fetchDepth}`)
427-
}
428-
429-
if (recursive) {
430-
args.push('--recursive')
431-
}
432-
433-
await this.execGit(args)
434-
}
435-
} else {
436-
const args = ['-c', 'protocol.version=2']
437-
args.push('submodule', 'update', '--init', '--force')
438-
if (fetchDepth > 0) {
439-
args.push(`--depth=${fetchDepth}`)
440-
}
441-
442-
if (recursive) {
443-
args.push('--recursive')
444-
}
421+
const args = ['-c', 'protocol.version=2']
422+
args.push(
423+
'submodule',
424+
'update',
425+
'--init',
426+
'--force',
427+
...submoduleDirectories
428+
)
429+
if (fetchDepth > 0) {
430+
args.push(`--depth=${fetchDepth}`)
431+
}
445432

446-
await this.execGit(args)
433+
if (recursive) {
434+
args.push('--recursive')
447435
}
436+
437+
await this.execGit(args)
448438
}
449439

450440
async submoduleStatus(): Promise<boolean> {

‎src/git-source-settings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export interface IGitSourceSettings {
7777
/**
7878
* Indicates which submodule paths to checkout
7979
*/
80-
submoduleDirectories: string[] | null
80+
submoduleDirectories: string[]
8181

8282
/**
8383
* The auth token to use when fetching the repository

‎src/input-helper.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
125125
// Submodules
126126
result.submodules = false
127127
result.nestedSubmodules = false
128-
result.submoduleDirectories = null
128+
result.submoduleDirectories = []
129129
const submodulesString = (core.getInput('submodules') || '').toUpperCase()
130130
if (submodulesString == 'RECURSIVE') {
131131
result.submodules = true
@@ -138,8 +138,6 @@ export async function getInputs(): Promise<IGitSourceSettings> {
138138
if (submoduleDirectories.length > 0) {
139139
result.submoduleDirectories = submoduleDirectories
140140
if (!result.submodules) result.submodules = true
141-
} else {
142-
result.submoduleDirectories = null
143141
}
144142

145143
core.debug(`submodules = ${result.submodules}`)

0 commit comments

Comments
 (0)
Failed to load comments.