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:
authoreric sciple <ericsciple@users.noreply.github.com>2019-12-12 13:16:16 -0500
committerGitHub <noreply@github.com>2019-12-12 13:16:16 -0500
commit25ac60e43ded675f082e10f444b0ad95ea43622e (patch)
tree4f254bf120e072e899f70c2646541eeec6fbbd63 /src/git-command-manager.ts
parentf60b14d6faba41537d0983497a96349d75b1b481 (diff)
fallback to REST API to download repo (#104)
Diffstat (limited to 'src/git-command-manager.ts')
-rw-r--r--src/git-command-manager.ts63
1 files changed, 15 insertions, 48 deletions
diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts
index 6e4f22f..ddd5ec6 100644
--- a/src/git-command-manager.ts
+++ b/src/git-command-manager.ts
@@ -3,8 +3,13 @@ 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 retryHelper from './retry-helper'
import {GitVersion} from './git-version'
+// Auth header not supported before 2.9
+// Wire protocol v2 not supported before 2.18
+export const MinimumGitVersion = new GitVersion('2.18')
+
export interface IGitCommandManager {
branchDelete(remote: boolean, branch: string): Promise<void>
branchExists(remote: boolean, pattern: string): Promise<boolean>
@@ -150,22 +155,10 @@ class GitCommandManager {
args.push(arg)
}
- let attempt = 1
- const maxAttempts = 3
- while (attempt <= maxAttempts) {
- const allowAllExitCodes = attempt < maxAttempts
- const output = await this.execGit(args, allowAllExitCodes)
- if (output.exitCode === 0) {
- break
- }
-
- const seconds = this.getRandomIntInclusive(1, 10)
- core.warning(
- `Git fetch failed with exit code ${output.exitCode}. Waiting ${seconds} seconds before trying again.`
- )
- await this.sleep(seconds * 1000)
- attempt++
- }
+ const that = this
+ await retryHelper.execute(async () => {
+ await that.execGit(args)
+ })
}
getWorkingDirectory(): string {
@@ -188,22 +181,10 @@ class GitCommandManager {
async lfsFetch(ref: string): Promise<void> {
const args = ['lfs', 'fetch', 'origin', ref]
- let attempt = 1
- const maxAttempts = 3
- while (attempt <= maxAttempts) {
- const allowAllExitCodes = attempt < maxAttempts
- const output = await this.execGit(args, allowAllExitCodes)
- if (output.exitCode === 0) {
- break
- }
-
- const seconds = this.getRandomIntInclusive(1, 10)
- core.warning(
- `Git lfs fetch failed with exit code ${output.exitCode}. Waiting ${seconds} seconds before trying again.`
- )
- await this.sleep(seconds * 1000)
- attempt++
- }
+ const that = this
+ await retryHelper.execute(async () => {
+ await that.execGit(args)
+ })
}
async lfsInstall(): Promise<void> {
@@ -338,13 +319,9 @@ class GitCommandManager {
}
// Minimum git version
- // Note:
- // - Auth header not supported before 2.9
- // - Wire protocol v2 not supported before 2.18
- const minimumGitVersion = new GitVersion('2.18')
- if (!gitVersion.checkMinimum(minimumGitVersion)) {
+ if (!gitVersion.checkMinimum(MinimumGitVersion)) {
throw new Error(
- `Minimum required git version is ${minimumGitVersion}. Your git ('${this.gitPath}') is ${gitVersion}`
+ `Minimum required git version is ${MinimumGitVersion}. Your git ('${this.gitPath}') is ${gitVersion}`
)
}
@@ -381,16 +358,6 @@ class GitCommandManager {
core.debug(`Set git useragent to: ${gitHttpUserAgent}`)
this.gitEnv['GIT_HTTP_USER_AGENT'] = gitHttpUserAgent
}
-
- private getRandomIntInclusive(minimum: number, maximum: number): number {
- minimum = Math.floor(minimum)
- maximum = Math.floor(maximum)
- return Math.floor(Math.random() * (maximum - minimum + 1)) + minimum
- }
-
- private async sleep(milliseconds): Promise<void> {
- return new Promise(resolve => setTimeout(resolve, milliseconds))
- }
}
class GitOutput {