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

Add string[] option to submodules #1866

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Simplified the submoduleDirectories
  • Loading branch information
Maddimax committed Aug 28, 2024
commit 7618b1f4010086b3da48eaecce4a26738f216281
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
# Default: false
submodules: ''

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

2 changes: 1 addition & 1 deletion __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
@@ -813,7 +813,7 @@ async function setup(testName: string): Promise<void> {
lfs: false,
submodules: false,
nestedSubmodules: false,
submoduleDirectories: null,
submoduleDirectories: [],
persistCredentials: true,
ref: 'refs/heads/main',
repositoryName: 'my-repo',
2 changes: 1 addition & 1 deletion __test__/input-helper.test.ts
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ describe('input-helper tests', () => {
expect(settings.showProgress).toBe(true)
expect(settings.lfs).toBe(false)
expect(settings.ref).toBe('refs/heads/some-ref')
expect(settings.submoduleDirectories).toBe(null)
expect(settings.submoduleDirectories).toStrictEqual([])
expect(settings.repositoryName).toBe('some-repo')
expect(settings.repositoryOwner).toBe('some-owner')
expect(settings.repositoryPath).toBe(gitHubWorkspace)
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ inputs:
default: false
submodule-directories:
description: >
A list of submodules to use when `submodules` is `true`.
A list of submodules to checkout.
default: null
set-safe-directory:
description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
34 changes: 8 additions & 26 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -797,30 +797,15 @@ class GitCommandManager {
}
submoduleUpdate(fetchDepth, recursive, submoduleDirectories) {
return __awaiter(this, void 0, void 0, function* () {
if (submoduleDirectories) {
for (const submodule of submoduleDirectories) {
const args = ['-c', 'protocol.version=2'];
args.push('submodule', 'update', '--init', '--force', submodule);
if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`);
}
if (recursive) {
args.push('--recursive');
}
yield this.execGit(args);
}
const args = ['-c', 'protocol.version=2'];
args.push('submodule', 'update', '--init', '--force', ...submoduleDirectories);
if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`);
}
else {
const args = ['-c', 'protocol.version=2'];
args.push('submodule', 'update', '--init', '--force');
if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`);
}
if (recursive) {
args.push('--recursive');
}
yield this.execGit(args);
if (recursive) {
args.push('--recursive');
}
yield this.execGit(args);
});
}
submoduleStatus() {
@@ -1820,7 +1805,7 @@ function getInputs() {
// Submodules
result.submodules = false;
result.nestedSubmodules = false;
result.submoduleDirectories = null;
result.submoduleDirectories = [];
const submodulesString = (core.getInput('submodules') || '').toUpperCase();
if (submodulesString == 'RECURSIVE') {
result.submodules = true;
@@ -1835,9 +1820,6 @@ function getInputs() {
if (!result.submodules)
result.submodules = true;
}
else {
result.submoduleDirectories = null;
}
core.debug(`submodules = ${result.submodules}`);
core.debug(`recursive submodules = ${result.nestedSubmodules}`);
core.debug(`submodule directories = ${result.submoduleDirectories}`);
44 changes: 17 additions & 27 deletions src/git-command-manager.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ export interface IGitCommandManager {
submoduleUpdate(
fetchDepth: number,
recursive: boolean,
submoduleDirectories: string[] | null
submoduleDirectories: string[]
): Promise<void>
submoduleStatus(): Promise<boolean>
tagExists(pattern: string): Promise<boolean>
@@ -416,35 +416,25 @@ class GitCommandManager {
async submoduleUpdate(
fetchDepth: number,
recursive: boolean,
submoduleDirectories: string[] | null
submoduleDirectories: string[]
): Promise<void> {
if (submoduleDirectories) {
for (const submodule of submoduleDirectories) {
const args = ['-c', 'protocol.version=2']
args.push('submodule', 'update', '--init', '--force', submodule)
if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`)
}

if (recursive) {
args.push('--recursive')
}

await this.execGit(args)
}
} else {
const args = ['-c', 'protocol.version=2']
args.push('submodule', 'update', '--init', '--force')
if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`)
}

if (recursive) {
args.push('--recursive')
}
const args = ['-c', 'protocol.version=2']
args.push(
'submodule',
'update',
'--init',
'--force',
...submoduleDirectories
)
if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`)
}

await this.execGit(args)
if (recursive) {
args.push('--recursive')
}

await this.execGit(args)
}

async submoduleStatus(): Promise<boolean> {
2 changes: 1 addition & 1 deletion src/git-source-settings.ts
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ export interface IGitSourceSettings {
/**
* Indicates which submodule paths to checkout
*/
submoduleDirectories: string[] | null
submoduleDirectories: string[]

/**
* The auth token to use when fetching the repository
4 changes: 1 addition & 3 deletions src/input-helper.ts
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
// Submodules
result.submodules = false
result.nestedSubmodules = false
result.submoduleDirectories = null
result.submoduleDirectories = []
const submodulesString = (core.getInput('submodules') || '').toUpperCase()
if (submodulesString == 'RECURSIVE') {
result.submodules = true
@@ -138,8 +138,6 @@ export async function getInputs(): Promise<IGitSourceSettings> {
if (submoduleDirectories.length > 0) {
result.submoduleDirectories = submoduleDirectories
if (!result.submodules) result.submodules = true
} else {
result.submoduleDirectories = null
}

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