diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/get_git.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/get_git.go | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/get_git.go b/vendor/github.com/hashicorp/go-getter/get_git.go index 0728139..cb1d029 100644 --- a/vendor/github.com/hashicorp/go-getter/get_git.go +++ b/vendor/github.com/hashicorp/go-getter/get_git.go | |||
@@ -11,6 +11,7 @@ import ( | |||
11 | "strings" | 11 | "strings" |
12 | 12 | ||
13 | urlhelper "github.com/hashicorp/go-getter/helper/url" | 13 | urlhelper "github.com/hashicorp/go-getter/helper/url" |
14 | "github.com/hashicorp/go-safetemp" | ||
14 | "github.com/hashicorp/go-version" | 15 | "github.com/hashicorp/go-version" |
15 | ) | 16 | ) |
16 | 17 | ||
@@ -105,13 +106,11 @@ func (g *GitGetter) Get(dst string, u *url.URL) error { | |||
105 | // GetFile for Git doesn't support updating at this time. It will download | 106 | // GetFile for Git doesn't support updating at this time. It will download |
106 | // the file every time. | 107 | // the file every time. |
107 | func (g *GitGetter) GetFile(dst string, u *url.URL) error { | 108 | func (g *GitGetter) GetFile(dst string, u *url.URL) error { |
108 | td, err := ioutil.TempDir("", "getter-git") | 109 | td, tdcloser, err := safetemp.Dir("", "getter") |
109 | if err != nil { | 110 | if err != nil { |
110 | return err | 111 | return err |
111 | } | 112 | } |
112 | if err := os.RemoveAll(td); err != nil { | 113 | defer tdcloser.Close() |
113 | return err | ||
114 | } | ||
115 | 114 | ||
116 | // Get the filename, and strip the filename from the URL so we can | 115 | // Get the filename, and strip the filename from the URL so we can |
117 | // just get the repository directly. | 116 | // just get the repository directly. |
@@ -180,17 +179,34 @@ func (g *GitGetter) fetchSubmodules(dst, sshKeyFile string) error { | |||
180 | // setupGitEnv sets up the environment for the given command. This is used to | 179 | // 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. | 180 | // pass configuration data to git and ssh and enables advanced cloning methods. |
182 | func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) { | 181 | func setupGitEnv(cmd *exec.Cmd, sshKeyFile string) { |
183 | var sshOpts []string | 182 | const gitSSHCommand = "GIT_SSH_COMMAND=" |
183 | var sshCmd []string | ||
184 | |||
185 | // If we have an existing GIT_SSH_COMMAND, we need to append our options. | ||
186 | // We will also remove our old entry to make sure the behavior is the same | ||
187 | // with versions of Go < 1.9. | ||
188 | env := os.Environ() | ||
189 | for i, v := range env { | ||
190 | if strings.HasPrefix(v, gitSSHCommand) { | ||
191 | sshCmd = []string{v} | ||
192 | |||
193 | env[i], env[len(env)-1] = env[len(env)-1], env[i] | ||
194 | env = env[:len(env)-1] | ||
195 | break | ||
196 | } | ||
197 | } | ||
198 | |||
199 | if len(sshCmd) == 0 { | ||
200 | sshCmd = []string{gitSSHCommand + "ssh"} | ||
201 | } | ||
184 | 202 | ||
185 | if sshKeyFile != "" { | 203 | if sshKeyFile != "" { |
186 | // We have an SSH key temp file configured, tell ssh about this. | 204 | // We have an SSH key temp file configured, tell ssh about this. |
187 | sshOpts = append(sshOpts, "-i", sshKeyFile) | 205 | sshCmd = append(sshCmd, "-i", sshKeyFile) |
188 | } | 206 | } |
189 | 207 | ||
190 | cmd.Env = append(os.Environ(), | 208 | env = append(env, strings.Join(sshCmd, " ")) |
191 | // Set the ssh command to use for clones. | 209 | cmd.Env = env |
192 | "GIT_SSH_COMMAND=ssh "+strings.Join(sshOpts, " "), | ||
193 | ) | ||
194 | } | 210 | } |
195 | 211 | ||
196 | // checkGitVersion is used to check the version of git installed on the system | 212 | // checkGitVersion is used to check the version of git installed on the system |