1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2024-11-24 12:39:16 +01:00

add shallow-since option

This commit is contained in:
satotake 2021-10-20 23:56:37 +09:00
parent 3d677ac575
commit b0b939aaa5
8 changed files with 52 additions and 9 deletions

View file

@ -90,9 +90,11 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous
clean: '' clean: ''
# Number of commits to fetch. 0 indicates all history for all branches and tags. # Number of commits to fetch. 0 indicates all history for all branches and tags.
# Default: 1
fetch-depth: '' fetch-depth: ''
# Date like `2days` or `1970-01-01`. Fetch a history after the specified time.
shallow-since: ''
# Whether to download Git-LFS files # Whether to download Git-LFS files
# Default: false # Default: false
lfs: '' lfs: ''

View file

@ -760,6 +760,7 @@ async function setup(testName: string): Promise<void> {
clean: true, clean: true,
commit: '', commit: '',
fetchDepth: 1, fetchDepth: 1,
shallowSince: '',
lfs: false, lfs: false,
submodules: false, submodules: false,
nestedSubmodules: false, nestedSubmodules: false,

View file

@ -55,7 +55,8 @@ inputs:
default: true default: true
fetch-depth: fetch-depth:
description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.' description: 'Number of commits to fetch. 0 indicates all history for all branches and tags.'
default: 1 shallow-since:
description: 'Date like `2days` or `1970-01-01`. Fetch a history after the specified time.'
lfs: lfs:
description: 'Whether to download Git-LFS files' description: 'Whether to download Git-LFS files'
default: false default: false

View file

@ -72,6 +72,8 @@ We want to take this opportunity to make behavioral changes, from v1. This docum
fetch-depth: fetch-depth:
description: 'Number of commits to fetch. 0 indicates all history for all tags and branches.' description: 'Number of commits to fetch. 0 indicates all history for all tags and branches.'
default: 1 default: 1
shallow-since:
description: 'Date like `2days` or `1970-01-01`. Fetch a history after the specified time.'
lfs: lfs:
description: 'Whether to download Git-LFS files' description: 'Whether to download Git-LFS files'
default: false default: false
@ -155,7 +157,7 @@ Fetch only the SHA being built and set depth=1. This significantly reduces the f
If a SHA isn't available (e.g. multi repo), then fetch only the specified ref with depth=1. If a SHA isn't available (e.g. multi repo), then fetch only the specified ref with depth=1.
The input `fetch-depth` can be used to control the depth. The input `fetch-depth` and `shallow-since` can be used to control the depth.
Note: Note:
- Fetching a single commit is supported by Git wire protocol version 2. The git client uses protocol version 0 by default. The desired protocol version can be overridden in the git config or on the fetch command line invocation (`-c protocol.version=2`). We will override on the fetch command line, for transparency. - Fetching a single commit is supported by Git wire protocol version 2. The git client uses protocol version 0 by default. The desired protocol version can be overridden in the git config or on the fetch command line invocation (`-c protocol.version=2`). We will override on the fetch command line, for transparency.

View file

@ -24,7 +24,11 @@ export interface IGitCommandManager {
globalConfig?: boolean globalConfig?: boolean
): Promise<void> ): Promise<void>
configExists(configKey: string, globalConfig?: boolean): Promise<boolean> 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> getDefaultBranch(repositoryUrl: string): Promise<string>
getWorkingDirectory(): string getWorkingDirectory(): string
init(): Promise<void> init(): Promise<void>
@ -39,7 +43,11 @@ export interface IGitCommandManager {
shaExists(sha: string): Promise<boolean> shaExists(sha: string): Promise<boolean>
submoduleForeach(command: string, recursive: boolean): Promise<string> submoduleForeach(command: string, recursive: boolean): Promise<string>
submoduleSync(recursive: boolean): Promise<void> 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> tagExists(pattern: string): Promise<boolean>
tryClean(): Promise<boolean> tryClean(): Promise<boolean>
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean> tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
@ -168,7 +176,11 @@ class GitCommandManager {
return output.exitCode === 0 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'] const args = ['-c', 'protocol.version=2', 'fetch']
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) { if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
args.push('--no-tags') args.push('--no-tags')
@ -177,6 +189,8 @@ class GitCommandManager {
args.push('--prune', '--progress', '--no-recurse-submodules') args.push('--prune', '--progress', '--no-recurse-submodules')
if (fetchDepth && fetchDepth > 0) { if (fetchDepth && fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`) args.push(`--depth=${fetchDepth}`)
} else if (shallowSince) {
args.push(`--shallow-since=${shallowSince}`)
} else if ( } else if (
fshelper.fileExistsSync( fshelper.fileExistsSync(
path.join(this.workingDirectory, '.git', 'shallow') path.join(this.workingDirectory, '.git', 'shallow')
@ -310,12 +324,19 @@ class GitCommandManager {
await this.execGit(args) 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'] const args = ['-c', 'protocol.version=2']
args.push('submodule', 'update', '--init', '--force') args.push('submodule', 'update', '--init', '--force')
if (fetchDepth > 0) { if (fetchDepth > 0) {
args.push(`--depth=${fetchDepth}`) args.push(`--depth=${fetchDepth}`)
} }
if (shallowSince) {
args.push(`--shallow-since=${shallowSince}`)
}
if (recursive) { if (recursive) {
args.push('--recursive') args.push('--recursive')

View file

@ -141,7 +141,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
} }
} else { } else {
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit) const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
await git.fetch(refSpec, settings.fetchDepth) await git.fetch(refSpec, settings.fetchDepth, settings.shallowSince)
} }
core.endGroup() core.endGroup()
@ -181,7 +181,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
await git.submoduleSync(settings.nestedSubmodules) await git.submoduleSync(settings.nestedSubmodules)
await git.submoduleUpdate( await git.submoduleUpdate(
settings.fetchDepth, settings.fetchDepth,
settings.nestedSubmodules settings.nestedSubmodules,
settings.shallowSince
) )
await git.submoduleForeach( await git.submoduleForeach(
'git config --local gc.auto 0', 'git config --local gc.auto 0',

View file

@ -34,6 +34,11 @@ export interface IGitSourceSettings {
*/ */
fetchDepth: number fetchDepth: number
/**
* The date which a history after is fetched
*/
shallowSince: string
/** /**
* Indicates whether to fetch LFS objects * Indicates whether to fetch LFS objects
*/ */

View file

@ -88,6 +88,16 @@ export function getInputs(): IGitSourceSettings {
} }
core.debug(`fetch depth = ${result.fetchDepth}`) 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 // LFS
result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE' result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE'
core.debug(`lfs = ${result.lfs}`) core.debug(`lfs = ${result.lfs}`)