mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-07-27 02:24:52 +02:00
Add string[] option to submodules
Allows checking out only specific submodules instead of all
This commit is contained in:
parent
9a9194f871
commit
b6625bb44a
10 changed files with 128 additions and 22 deletions
|
@ -54,7 +54,11 @@ export interface IGitCommandManager {
|
|||
shaExists(sha: string): Promise<boolean>
|
||||
submoduleForeach(command: string, recursive: boolean): Promise<string>
|
||||
submoduleSync(recursive: boolean): Promise<void>
|
||||
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
|
||||
submoduleUpdate(
|
||||
fetchDepth: number,
|
||||
recursive: boolean,
|
||||
submoduleDirectories: string[] | null
|
||||
): Promise<void>
|
||||
submoduleStatus(): Promise<boolean>
|
||||
tagExists(pattern: string): Promise<boolean>
|
||||
tryClean(): Promise<boolean>
|
||||
|
@ -409,18 +413,38 @@ class GitCommandManager {
|
|||
await this.execGit(args)
|
||||
}
|
||||
|
||||
async submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> {
|
||||
const args = ['-c', 'protocol.version=2']
|
||||
args.push('submodule', 'update', '--init', '--force')
|
||||
if (fetchDepth > 0) {
|
||||
args.push(`--depth=${fetchDepth}`)
|
||||
}
|
||||
async submoduleUpdate(
|
||||
fetchDepth: number,
|
||||
recursive: boolean,
|
||||
submoduleDirectories: string[] | null
|
||||
): 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')
|
||||
}
|
||||
if (recursive) {
|
||||
args.push('--recursive')
|
||||
}
|
||||
|
||||
await this.execGit(args)
|
||||
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')
|
||||
}
|
||||
|
||||
await this.execGit(args)
|
||||
}
|
||||
}
|
||||
|
||||
async submoduleStatus(): Promise<boolean> {
|
||||
|
|
|
@ -242,7 +242,11 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
// Checkout submodules
|
||||
core.startGroup('Fetching submodules')
|
||||
await git.submoduleSync(settings.nestedSubmodules)
|
||||
await git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules)
|
||||
await git.submoduleUpdate(
|
||||
settings.fetchDepth,
|
||||
settings.nestedSubmodules,
|
||||
settings.submoduleDirectories
|
||||
)
|
||||
await git.submoduleForeach(
|
||||
'git config --local gc.auto 0',
|
||||
settings.nestedSubmodules
|
||||
|
|
|
@ -74,6 +74,11 @@ export interface IGitSourceSettings {
|
|||
*/
|
||||
nestedSubmodules: boolean
|
||||
|
||||
/**
|
||||
* Indicates which submodule paths to checkout
|
||||
*/
|
||||
submoduleDirectories: string[] | null
|
||||
|
||||
/**
|
||||
* The auth token to use when fetching the repository
|
||||
*/
|
||||
|
|
|
@ -125,6 +125,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||
// Submodules
|
||||
result.submodules = false
|
||||
result.nestedSubmodules = false
|
||||
result.submoduleDirectories = null
|
||||
const submodulesString = (core.getInput('submodules') || '').toUpperCase()
|
||||
if (submodulesString == 'RECURSIVE') {
|
||||
result.submodules = true
|
||||
|
@ -132,9 +133,18 @@ export async function getInputs(): Promise<IGitSourceSettings> {
|
|||
} else if (submodulesString == 'TRUE') {
|
||||
result.submodules = true
|
||||
}
|
||||
|
||||
const submoduleDirectories = core.getMultilineInput('submodule-directories')
|
||||
if (submoduleDirectories.length > 0) {
|
||||
result.submoduleDirectories = submoduleDirectories
|
||||
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}`)
|
||||
// Auth token
|
||||
result.authToken = core.getInput('token', {required: true})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue