diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-05-27 09:54:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-27 09:54:28 -0400 |
| commit | 1af3b46e902378dcbdf104a32ddae1644c64c366 (patch) | |
| tree | eb40b22d94abbd6860bb2ec1eac5b1ca62ea542a /src/git-command-manager.ts | |
| parent | 31d9f35c90667154e76ccca096898caab3e5bba7 (diff) | |
Fetch all history for all tags and branches when fetch-depth=0 (#258)
Diffstat (limited to 'src/git-command-manager.ts')
| -rw-r--r-- | src/git-command-manager.ts | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 495075a..9d2d45f 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -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) { |
