diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-12 11:42:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-12 11:42:38 -0400 |
| commit | 6f1b729011b34bc28608462b6293df85180aba9c (patch) | |
| tree | 21ab78013bc7cc88344c3cb9feaaa42213b20407 /src | |
| parent | 1b406b27feed694fb3a05a638c92124514baa6ea (diff) | |
persist core.sshCommand for submodules (#184)
* persist core.sshCommand for submodules
* update verbiage; add comments
* fail when submodules or ssh-key and fallback to REST API
Diffstat (limited to 'src')
| -rw-r--r-- | src/git-auth-helper.ts | 23 | ||||
| -rw-r--r-- | src/git-source-provider.ts | 10 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index 7418c7c..06e8912 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -37,6 +37,7 @@ class GitAuthHelper { private readonly tokenPlaceholderConfigValue: string private readonly insteadOfKey: string = `url.https://${HOSTNAME}/.insteadOf` private readonly insteadOfValue: string = `git@${HOSTNAME}:` + private sshCommand = '' private sshKeyPath = '' private sshKnownHostsPath = '' private temporaryHomePath = '' @@ -144,8 +145,14 @@ class GitAuthHelper { this.replaceTokenPlaceholder(configPath) } - // Configure HTTPS instead of SSH - if (!this.settings.sshKey) { + if (this.settings.sshKey) { + // Configure core.sshCommand + await this.git.submoduleForeach( + `git config --local '${SSH_COMMAND_KEY}' '${this.sshCommand}'`, + this.settings.nestedSubmodules + ) + } else { + // Configure HTTPS instead of SSH await this.git.submoduleForeach( `git config --local '${this.insteadOfKey}' '${this.insteadOfValue}'`, this.settings.nestedSubmodules @@ -218,21 +225,21 @@ class GitAuthHelper { // Configure GIT_SSH_COMMAND const sshPath = await io.which('ssh', true) - let sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename( + this.sshCommand = `"${sshPath}" -i "$RUNNER_TEMP/${path.basename( this.sshKeyPath )}"` if (this.settings.sshStrict) { - sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no' + this.sshCommand += ' -o StrictHostKeyChecking=yes -o CheckHostIP=no' } - sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename( + this.sshCommand += ` -o "UserKnownHostsFile=$RUNNER_TEMP/${path.basename( this.sshKnownHostsPath )}"` - core.info(`Temporarily overriding GIT_SSH_COMMAND=${sshCommand}`) - this.git.setEnvironmentVariable('GIT_SSH_COMMAND', sshCommand) + core.info(`Temporarily overriding GIT_SSH_COMMAND=${this.sshCommand}`) + this.git.setEnvironmentVariable('GIT_SSH_COMMAND', this.sshCommand) // Configure core.sshCommand if (this.settings.persistCredentials) { - await this.git.config(SSH_COMMAND_KEY, sshCommand) + await this.git.config(SSH_COMMAND_KEY, this.sshCommand) } } diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 7ce9fb7..4bce702 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -57,6 +57,16 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { core.info( `To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH` ) + if (settings.submodules) { + throw new Error( + `Input 'submodules' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.` + ) + } else if (settings.sshKey) { + throw new Error( + `Input 'ssh-key' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH.` + ) + } + await githubApiHelper.downloadRepository( settings.authToken, settings.repositoryOwner, |
