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-directory-helper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/git-directory-helper.ts')
-rw-r--r--src/git-directory-helper.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/git-directory-helper.ts b/src/git-directory-helper.ts
index bfaa4a9..a7d6ae8 100644
--- a/src/git-directory-helper.ts
+++ b/src/git-directory-helper.ts
@@ -1,18 +1,30 @@
+import * as assert from 'assert'
import * as core from '@actions/core'
import * as fs from 'fs'
import * as fsHelper from './fs-helper'
import * as io from '@actions/io'
import * as path from 'path'
import {IGitCommandManager} from './git-command-manager'
+import {IGitSourceSettings} from './git-source-settings'
export async function prepareExistingDirectory(
git: IGitCommandManager | undefined,
repositoryPath: string,
- repositoryUrl: string,
+ preferredRemoteUrl: string,
+ allowedRemoteUrls: string[],
clean: boolean
): Promise<void> {
+ assert.ok(repositoryPath, 'Expected repositoryPath to be defined')
+ assert.ok(preferredRemoteUrl, 'Expected preferredRemoteUrl to be defined')
+ assert.ok(allowedRemoteUrls, 'Expected allowedRemoteUrls to be defined')
+ assert.ok(allowedRemoteUrls.length, 'Expected allowedRemoteUrls to have at least one value')
+
+ // Indicates whether to delete the directory contents
let remove = false
+ // The remote URL
+ let remoteUrl: string
+
// Check whether using git or REST API
if (!git) {
remove = true
@@ -20,7 +32,7 @@ export async function prepareExistingDirectory(
// Fetch URL does not match
else if (
!fsHelper.directoryExistsSync(path.join(repositoryPath, '.git')) ||
- repositoryUrl !== (await git.tryGetFetchUrl())
+ allowedRemoteUrls.indexOf((remoteUrl = await git.tryGetRemoteUrl())) < 0
) {
remove = true
} else {
@@ -72,6 +84,11 @@ export async function prepareExistingDirectory(
)
}
}
+
+ // Update to the preferred remote URL
+ if (remoteUrl !== preferredRemoteUrl) {
+ await git.setRemoteUrl(preferredRemoteUrl)
+ }
} catch (error) {
core.warning(
`Unable to prepare the existing repository. The repository will be recreated instead.`