mirror of
https://github.com/actions/checkout.git
synced 2025-07-21 14:08:31 +02:00
add shallow-since
option
This commit is contained in:
parent
3d677ac575
commit
b0b939aaa5
8 changed files with 52 additions and 9 deletions
|
@ -24,7 +24,11 @@ export interface IGitCommandManager {
|
|||
globalConfig?: boolean
|
||||
): Promise<void>
|
||||
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
|
||||
fetch(refSpec: string[], fetchDepth?: number): Promise<void>
|
||||
fetch(
|
||||
refSpec: string[],
|
||||
fetchDepth?: number,
|
||||
shallowSince?: string
|
||||
): Promise<void>
|
||||
getDefaultBranch(repositoryUrl: string): Promise<string>
|
||||
getWorkingDirectory(): string
|
||||
init(): Promise<void>
|
||||
|
@ -39,7 +43,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,
|
||||
shallowSince?: string
|
||||
): Promise<void>
|
||||
tagExists(pattern: string): Promise<boolean>
|
||||
tryClean(): Promise<boolean>
|
||||
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
|
||||
|
@ -168,7 +176,11 @@ class GitCommandManager {
|
|||
return output.exitCode === 0
|
||||
}
|
||||
|
||||
async fetch(refSpec: string[], fetchDepth?: number): Promise<void> {
|
||||
async fetch(
|
||||
refSpec: string[],
|
||||
fetchDepth?: number,
|
||||
shallowSince?: string
|
||||
): Promise<void> {
|
||||
const args = ['-c', 'protocol.version=2', 'fetch']
|
||||
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
|
||||
args.push('--no-tags')
|
||||
|
@ -177,6 +189,8 @@ class GitCommandManager {
|
|||
args.push('--prune', '--progress', '--no-recurse-submodules')
|
||||
if (fetchDepth && fetchDepth > 0) {
|
||||
args.push(`--depth=${fetchDepth}`)
|
||||
} else if (shallowSince) {
|
||||
args.push(`--shallow-since=${shallowSince}`)
|
||||
} else if (
|
||||
fshelper.fileExistsSync(
|
||||
path.join(this.workingDirectory, '.git', 'shallow')
|
||||
|
@ -310,12 +324,19 @@ class GitCommandManager {
|
|||
await this.execGit(args)
|
||||
}
|
||||
|
||||
async submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void> {
|
||||
async submoduleUpdate(
|
||||
fetchDepth: number,
|
||||
recursive: boolean,
|
||||
shallowSince?: string
|
||||
): Promise<void> {
|
||||
const args = ['-c', 'protocol.version=2']
|
||||
args.push('submodule', 'update', '--init', '--force')
|
||||
if (fetchDepth > 0) {
|
||||
args.push(`--depth=${fetchDepth}`)
|
||||
}
|
||||
if (shallowSince) {
|
||||
args.push(`--shallow-since=${shallowSince}`)
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
args.push('--recursive')
|
||||
|
|
|
@ -141,7 +141,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
}
|
||||
} else {
|
||||
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
|
||||
await git.fetch(refSpec, settings.fetchDepth)
|
||||
await git.fetch(refSpec, settings.fetchDepth, settings.shallowSince)
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
|
@ -181,7 +181,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
|||
await git.submoduleSync(settings.nestedSubmodules)
|
||||
await git.submoduleUpdate(
|
||||
settings.fetchDepth,
|
||||
settings.nestedSubmodules
|
||||
settings.nestedSubmodules,
|
||||
settings.shallowSince
|
||||
)
|
||||
await git.submoduleForeach(
|
||||
'git config --local gc.auto 0',
|
||||
|
|
|
@ -34,6 +34,11 @@ export interface IGitSourceSettings {
|
|||
*/
|
||||
fetchDepth: number
|
||||
|
||||
/**
|
||||
* The date which a history after is fetched
|
||||
*/
|
||||
shallowSince: string
|
||||
|
||||
/**
|
||||
* Indicates whether to fetch LFS objects
|
||||
*/
|
||||
|
|
|
@ -88,6 +88,16 @@ export function getInputs(): IGitSourceSettings {
|
|||
}
|
||||
core.debug(`fetch depth = ${result.fetchDepth}`)
|
||||
|
||||
// Shallow since
|
||||
result.shallowSince = core.getInput('shallow-since')
|
||||
core.debug(`shallow since = ${result.shallowSince}`)
|
||||
|
||||
if (result.fetchDepth > 0 && result.shallowSince) {
|
||||
throw new Error(
|
||||
'`fetch-depath` and `shallow-since` cannot be used at the same time'
|
||||
)
|
||||
}
|
||||
|
||||
// LFS
|
||||
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
|
||||
core.debug(`lfs = ${result.lfs}`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue