in plugins/toolkit/jetbrains-gateway/src/software/aws/toolkits/jetbrains/gateway/connection/AbstractSsmCommandExecutor.kt [102:156]
fun buildGitCloneCommand(remoteScriptPath: String, gitSettings: GitSettings.CloneGitSettings): GeneralCommandLine {
val repoUri = gitSettings.repo
val branch = gitSettings.branch
val gitHost = buildString {
append(repoUri.host)
if (repoUri.port != -1) {
append(":${repoUri.port}")
}
}
val isSsh = repoUri.scheme == "ssh"
val gitConfig = GitWrappers.getConfig()
val command = buildString {
if (gitConfig != null) {
val gitConfigArguments = buildString {
val name = gitConfig[GitWrappers.USER_NAME_KEY]
val email = gitConfig[GitWrappers.USER_EMAIL_KEY]
if (name != null) {
append(" -n '$name'")
}
if (email != null) {
append(" -e '$email'")
}
}
if (gitConfigArguments.isNotBlank()) {
append("$remoteScriptPath/git-config-user-email.sh $gitConfigArguments &&")
}
}
if (isSsh) {
append("$remoteScriptPath/keyscan-git-host.sh $gitHost &&")
}
append("$remoteScriptPath/git-clone.sh $repoUri $branch")
}
return newSshCommand()
.also { cmd ->
if (isSsh) {
cmd.addSshOption("-A")
val agent = SshAgentService.agentInstance()
if (agent is SocketBasedSshAgent) {
cmd.withEnvironment(mapOf(SSH_AGENT_VAR to agent.socket))
}
}
}
// force tty-allocation since providing a command turns it off
.addSshOption("-t")
.addToRemoteCommand(command)
.constructCommandLine()
}