mirror of
				https://github.com/actions/checkout.git
				synced 2025-10-31 11:13:59 +08:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 eric sciple
					eric sciple