|
|
|
|
@ -180,17 +180,34 @@ func (g *GitGetter) fetchSubmodules(dst, sshKeyFile string) error {
|
|
|
|
|
// setupGitEnv sets up the environment for the given command. This is used to
|
|
|
|
|
// pass configuration data to git and ssh and enables advanced cloning methods.
|
|
|
|
|
func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) {
|
|
|
|
|
var sshOpts []string
|
|
|
|
|
const gitSSHCommand = "GIT_SSH_COMMAND="
|
|
|
|
|
var sshCmd []string
|
|
|
|
|
|
|
|
|
|
// If we have an existing GIT_SSH_COMMAND, we need to append our options.
|
|
|
|
|
// We will also remove our old entry to make sure the behavior is the same
|
|
|
|
|
// with versions of Go < 1.9.
|
|
|
|
|
env := os.Environ()
|
|
|
|
|
for i, v := range env {
|
|
|
|
|
if strings.HasPrefix(v, gitSSHCommand) {
|
|
|
|
|
sshCmd = []string{v}
|
|
|
|
|
|
|
|
|
|
env[i], env[len(env)-1] = env[len(env)-1], env[i]
|
|
|
|
|
env = env[:len(env)-1]
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(sshCmd) == 0 {
|
|
|
|
|
sshCmd = []string{gitSSHCommand + "ssh"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if sshKeyFile != "" {
|
|
|
|
|
// We have an SSH key temp file configured, tell ssh about this.
|
|
|
|
|
sshOpts = append(sshOpts, "-i", sshKeyFile)
|
|
|
|
|
sshCmd = append(sshCmd, "-i", sshKeyFile)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd.Env = append(os.Environ(),
|
|
|
|
|
// Set the ssh command to use for clones.
|
|
|
|
|
"GIT_SSH_COMMAND=ssh "+strings.Join(sshOpts, " "),
|
|
|
|
|
)
|
|
|
|
|
env = append(env, strings.Join(sshCmd, " "))
|
|
|
|
|
cmd.Env = env
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// checkGitVersion is used to check the version of git installed on the system
|
|
|
|
|
|