Skip to content

Commit

Permalink
Git getter should check for SCP-style URLs and convert properly
Browse files Browse the repository at this point in the history
If a fully qualified URL like ssh://user@host:path is given, then the
detectors don't run (since the URL is valid). Therefore we must also
correct this directly in the getter.
  • Loading branch information
mitchellh committed Nov 17, 2018
1 parent 4e6a4f2 commit 6b4c590
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions get_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
}
}

// For SSH-style URLs, if they use the SCP syntax of host:path, then
// the URL will be mangled. We detect that here and correct the path.
// Example: host:path/bar will turn into host/path/bar
if u.Scheme == "ssh" {
if idx := strings.Index(u.Host, ":"); idx > -1 {
// Copy the URL so we don't modify the input
var newU url.URL = *u
u = &newU

// Path includes the part after the ':'.
u.Path = u.Host[idx+1:] + u.Path
if u.Path[0] != '/' {
u.Path = "/" + u.Path
}

// Host trims up to the :
u.Host = u.Host[:idx]
}
}

// Clone or update the repository
_, err := os.Stat(dst)
if err != nil && !os.IsNotExist(err) {
Expand Down

0 comments on commit 6b4c590

Please sign in to comment.