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-auth-helper.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2020-03-10 10:45:50 -0400
committerGitHub <noreply@github.com>2020-03-10 10:45:50 -0400
commitad8315eb967265115b59c3b9dc1516f8ac5917ba (patch)
treeb1fd9b514391749e3b6809073c250686b202a961 /src/git-auth-helper.ts
parent409c1e98cfd9d307759b66c12b2a69024d673ea3 (diff)
convert SSH URL to HTTPS (#179)
Diffstat (limited to 'src/git-auth-helper.ts')
-rw-r--r--src/git-auth-helper.ts17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts
index dd76fe9..3f36ff8 100644
--- a/src/git-auth-helper.ts
+++ b/src/git-auth-helper.ts
@@ -34,6 +34,8 @@ class GitAuthHelper {
private readonly settings: IGitSourceSettings
private readonly tokenConfigKey: string = `http.https://${HOSTNAME}/.extraheader`
private readonly tokenPlaceholderConfigValue: string
+ private readonly insteadOfKey: string = `url.https://${HOSTNAME}/.insteadOf`
+ private readonly insteadOfValue: string = `git@${HOSTNAME}:`
private temporaryHomePath = ''
private tokenConfigValue: string
@@ -92,13 +94,19 @@ class GitAuthHelper {
await fs.promises.writeFile(newGitConfigPath, '')
}
- // Configure the token
try {
+ // Override HOME
core.info(
`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`
)
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath)
+
+ // Configure the token
await this.configureToken(newGitConfigPath, true)
+
+ // Configure HTTPS instead of SSH
+ await this.git.tryConfigUnset(this.insteadOfKey, true)
+ await this.git.config(this.insteadOfKey, this.insteadOfValue, true)
} catch (err) {
// Unset in case somehow written to the real global config
core.info(
@@ -114,8 +122,13 @@ class GitAuthHelper {
// Configure a placeholder value. This approach avoids the credential being captured
// by process creation audit events, which are commonly logged. For more information,
// refer to https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/manage/component-updates/command-line-process-auditing
+ const commands = [
+ `git config --local "${this.tokenConfigKey}" "${this.tokenPlaceholderConfigValue}"`,
+ `git config --local "${this.insteadOfKey}" "${this.insteadOfValue}"`,
+ `git config --local --show-origin --name-only --get-regexp remote.origin.url`
+ ]
const output = await this.git.submoduleForeach(
- `git config "${this.tokenConfigKey}" "${this.tokenPlaceholderConfigValue}" && git config --local --show-origin --name-only --get-regexp remote.origin.url`,
+ commands.join(' && '),
this.settings.nestedSubmodules
)