@@ -99,7 +99,7 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
9999 }
100100
101101 // Lastly, download any/all submodules.
102- return g .fetchSubmodules (dst )
102+ return g .fetchSubmodules (dst , sshKeyFile )
103103}
104104
105105// GetFile for Git doesn't support updating at this time. It will download
@@ -141,7 +141,7 @@ func (g *GitGetter) checkout(dst string, ref string) error {
141141
142142func (g * GitGetter ) clone (dst , sshKeyFile string , u * url.URL ) error {
143143 cmd := exec .Command ("git" , "clone" , u .String (), dst )
144- addSSHKeyFile (cmd , sshKeyFile )
144+ setupGitEnv (cmd , sshKeyFile )
145145 return getRunCommand (cmd )
146146}
147147
@@ -165,28 +165,32 @@ func (g *GitGetter) update(dst, sshKeyFile, ref string) error {
165165
166166 cmd = exec .Command ("git" , "pull" , "--ff-only" )
167167 cmd .Dir = dst
168- addSSHKeyFile (cmd , sshKeyFile )
168+ setupGitEnv (cmd , sshKeyFile )
169169 return getRunCommand (cmd )
170170}
171171
172172// fetchSubmodules downloads any configured submodules recursively.
173- func (g * GitGetter ) fetchSubmodules (dst string ) error {
173+ func (g * GitGetter ) fetchSubmodules (dst , sshKeyFile string ) error {
174174 cmd := exec .Command ("git" , "submodule" , "update" , "--init" , "--recursive" )
175175 cmd .Dir = dst
176+ setupGitEnv (cmd , sshKeyFile )
176177 return getRunCommand (cmd )
177178}
178179
179- // addSSHKeyFile sets up the given SSH private key file such that it will
180- // be used by the "git" command during authentication. This is accomplished
181- // using a special environment variable, which is set on the provided cmd.
182- // If the sshKeyFile is empty, this is a noop.
183- func addSSHKeyFile (cmd * exec.Cmd , sshKeyFile string ) {
184- if sshKeyFile == "" {
185- return
186- }
187- cmd .Env = append (os .Environ (), "GIT_SSH_COMMAND=ssh " +
188- "-o StrictHostKeyChecking=no " +
189- "-i " + sshKeyFile )
180+ // setupGitEnv sets up the environment for the given command. This is used to
181+ // pass configuration data to git and ssh and enables advanced cloning methods.
182+ func setupGitEnv (cmd * exec.Cmd , sshKeyFile string ) {
183+ var sshOpts []string
184+
185+ if sshKeyFile != "" {
186+ // We have an SSH key temp file configured, tell ssh about this.
187+ sshOpts = append (sshOpts , "-i" , sshKeyFile )
188+ }
189+
190+ cmd .Env = append (os .Environ (),
191+ // Set the ssh command to use for clones.
192+ "GIT_SSH_COMMAND=ssh " + strings .Join (sshOpts , " " ),
193+ )
190194}
191195
192196// checkGitVersion is used to check the version of git installed on the system
0 commit comments