From 94ea861d9c2d89e28a27ce3111cd3ee24c97e759 Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Tue, 20 Mar 2018 10:19:09 -0700 Subject: [PATCH 1/2] Disable strict host key checking while cloning repo in repo-server --- util/git/git.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/git/git.go b/util/git/git.go index 4e59e7942aad9..a97cdf04ff167 100644 --- a/util/git/git.go +++ b/util/git/git.go @@ -42,7 +42,7 @@ func GetGitCommandEnvAndURL(repo, username, password string, sshPrivateKey strin if err != nil { return "", nil, err } - env = append(env, fmt.Sprintf("GIT_SSH_COMMAND=ssh -i %s", sshFile.Name())) + env = append(env, fmt.Sprintf("GIT_SSH_COMMAND=ssh -o StrictHostKeyChecking=no -i %s", sshFile.Name())) } } else { env = append(env, "GIT_ASKPASS=") From 00c30857873490466eb7cd845ca674ceeae94a12 Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Tue, 20 Mar 2018 10:29:48 -0700 Subject: [PATCH 2/2] Use correct environment during fetching git repo in repo-server --- util/git/client.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/util/git/client.go b/util/git/client.go index a8ee5fdcbbd50..06e6f8ec03e9b 100644 --- a/util/git/client.go +++ b/util/git/client.go @@ -32,17 +32,17 @@ func (m *NativeGitClient) CloneOrFetch(repo string, username string, password st needClone = err != nil } + repoURL, env, err := GetGitCommandEnvAndURL(repo, username, password, sshPrivateKey) + if err != nil { + return err + } + if needClone { _, err := exec.Command("rm", "-rf", repoPath).Output() if err != nil { return fmt.Errorf("unable to clean repo cache at %s: %v", repoPath, err) } - repoURL, env, err := GetGitCommandEnvAndURL(repo, username, password, sshPrivateKey) - if err != nil { - return err - } - log.Infof("Cloning %s to %s", repo, repoPath) cmd := exec.Command("git", "clone", repoURL, repoPath) cmd.Env = env @@ -54,6 +54,7 @@ func (m *NativeGitClient) CloneOrFetch(repo string, username string, password st log.Infof("Fetching %s", repo) // Fetch remote changes and delete all local branches cmd := exec.Command("sh", "-c", "git fetch --all && git checkout --detach HEAD") + cmd.Env = env cmd.Dir = repoPath _, err := cmd.Output() if err != nil {