Skip to content

Commit 3a12002

Browse files
committed
Let SSH config come from the client
1 parent 9e9c8be commit 3a12002

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

get_git.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,11 @@ func (g *GitGetter) fetchSubmodules(dst, sshKeyFile string) error {
180180
// setupGitEnv sets up the environment for the given command. This is used to
181181
// pass configuration data to git and ssh and enables advanced cloning methods.
182182
func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) {
183-
sshOpts := []string{
184-
// Batch mode prevents ssh from prompting for usernames, passwords, or
185-
// adding hosts into a known hosts file.
186-
"-o BatchMode=yes",
187-
}
183+
var sshOpts []string
188184

189185
if sshKeyFile != "" {
190186
// We have an SSH key temp file configured, tell ssh about this.
191-
sshOpts = append(sshOpts, "-i "+sshKeyFile)
187+
sshOpts = append(sshOpts, "-i", sshKeyFile)
192188
}
193189

194190
cmd.Env = append(os.Environ(),

get_git_test.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -294,26 +294,16 @@ func TestGitGetter_submodule(t *testing.T) {
294294
}
295295
}
296296

297-
func TestGitGetter_setupGitEnv(t *testing.T) {
298-
cmd := exec.Command("git")
299-
setupGitEnv(cmd, "")
300-
for _, v := range cmd.Env {
301-
if v == "GIT_SSH_COMMAND=ssh -o BatchMode=yes" {
302-
return
303-
}
304-
}
305-
t.Fatalf("expect default options to be set: %v", cmd.Env)
306-
}
307-
308297
func TestGitGetter_setupGitEnv_sshKey(t *testing.T) {
309-
cmd := exec.Command("git")
298+
cmd := exec.Command("/bin/sh", "-c", "echo -n $GIT_SSH_COMMAND")
310299
setupGitEnv(cmd, "/tmp/foo.pem")
311-
for _, v := range cmd.Env {
312-
if v == "GIT_SSH_COMMAND=ssh -o BatchMode=yes -i /tmp/foo.pem" {
313-
return
314-
}
300+
out, err := cmd.Output()
301+
if err != nil {
302+
t.Fatal(err)
303+
}
304+
if string(out) != "ssh -i /tmp/foo.pem" {
305+
t.Fatalf("unexpected GIT_SSH_COMMAND: %q", string(out))
315306
}
316-
t.Fatalf("expect default options to be set: %#v", cmd.Env)
317307
}
318308

319309
// gitRepo is a helper struct which controls a single temp git repo.

0 commit comments

Comments
 (0)