mirror of
https://code.forgejo.org/actions/checkout
synced 2025-04-28 11:34:25 +08:00
Fetch all history for all tags and branches when fetch-depth=0 (#258)
This commit is contained in:
parent
2ff2fbdea4
commit
e52d022eb5
9 changed files with 338 additions and 86 deletions
|
@ -3,6 +3,7 @@ import * as exec from '@actions/exec'
|
|||
import * as fshelper from './fs-helper'
|
||||
import * as io from '@actions/io'
|
||||
import * as path from 'path'
|
||||
import * as refHelper from './ref-helper'
|
||||
import * as regexpHelper from './regexp-helper'
|
||||
import * as retryHelper from './retry-helper'
|
||||
import {GitVersion} from './git-version'
|
||||
|
@ -23,7 +24,7 @@ export interface IGitCommandManager {
|
|||
globalConfig?: boolean
|
||||
): Promise<void>
|
||||
configExists(configKey: string, globalConfig?: boolean): Promise<boolean>
|
||||
fetch(fetchDepth: number, refSpec: string[]): Promise<void>
|
||||
fetch(refSpec: string[], fetchDepth?: number): Promise<void>
|
||||
getWorkingDirectory(): string
|
||||
init(): Promise<void>
|
||||
isDetached(): Promise<boolean>
|
||||
|
@ -32,7 +33,9 @@ export interface IGitCommandManager {
|
|||
log1(): Promise<string>
|
||||
remoteAdd(remoteName: string, remoteUrl: string): Promise<void>
|
||||
removeEnvironmentVariable(name: string): void
|
||||
revParse(ref: string): Promise<string>
|
||||
setEnvironmentVariable(name: string, value: string): void
|
||||
shaExists(sha: string): Promise<boolean>
|
||||
submoduleForeach(command: string, recursive: boolean): Promise<string>
|
||||
submoduleSync(recursive: boolean): Promise<void>
|
||||
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
|
||||
|
@ -164,17 +167,14 @@ class GitCommandManager {
|
|||
return output.exitCode === 0
|
||||
}
|
||||
|
||||
async fetch(fetchDepth: number, refSpec: string[]): Promise<void> {
|
||||
const args = [
|
||||
'-c',
|
||||
'protocol.version=2',
|
||||
'fetch',
|
||||
'--no-tags',
|
||||
'--prune',
|
||||
'--progress',
|
||||
'--no-recurse-submodules'
|
||||
]
|
||||
if (fetchDepth > 0) {
|
||||
async fetch(refSpec: string[], fetchDepth?: number): Promise<void> {
|
||||
const args = ['-c', 'protocol.version=2', 'fetch']
|
||||
if (!refSpec.some(x => x === refHelper.tagsRefSpec)) {
|
||||
args.push('--no-tags')
|
||||
}
|
||||
|
||||
args.push('--prune', '--progress', '--no-recurse-submodules')
|
||||
if (fetchDepth && fetchDepth > 0) {
|
||||
args.push(`--depth=${fetchDepth}`)
|
||||
} else if (
|
||||
fshelper.fileExistsSync(
|
||||
|
@ -238,10 +238,27 @@ class GitCommandManager {
|
|||
delete this.gitEnv[name]
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a ref to a SHA. For a branch or lightweight tag, the commit SHA is returned.
|
||||
* For an annotated tag, the tag SHA is returned.
|
||||
* @param {string} ref For example: 'refs/heads/master' or '/refs/tags/v1'
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async revParse(ref: string): Promise<string> {
|
||||
const output = await this.execGit(['rev-parse', ref])
|
||||
return output.stdout.trim()
|
||||
}
|
||||
|
||||
setEnvironmentVariable(name: string, value: string): void {
|
||||
this.gitEnv[name] = value
|
||||
}
|
||||
|
||||
async shaExists(sha: string): Promise<boolean> {
|
||||
const args = ['rev-parse', '--verify', '--quiet', `${sha}^{object}`]
|
||||
const output = await this.execGit(args, true)
|
||||
return output.exitCode === 0
|
||||
}
|
||||
|
||||
async submoduleForeach(command: string, recursive: boolean): Promise<string> {
|
||||
const args = ['submodule', 'foreach']
|
||||
if (recursive) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue