Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/git-command-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/git-command-manager.ts')
-rw-r--r--src/git-command-manager.ts41
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) {