Skip to content

Commit 6b4c590

Browse files
committed
Git getter should check for SCP-style URLs and convert properly
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.
1 parent 4e6a4f2 commit 6b4c590

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

get_git.go

+20
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ func (g *GitGetter) Get(dst string, u *url.URL) error {
7878
}
7979
}
8080

81+
// For SSH-style URLs, if they use the SCP syntax of host:path, then
82+
// the URL will be mangled. We detect that here and correct the path.
83+
// Example: host:path/bar will turn into host/path/bar
84+
if u.Scheme == "ssh" {
85+
if idx := strings.Index(u.Host, ":"); idx > -1 {
86+
// Copy the URL so we don't modify the input
87+
var newU url.URL = *u
88+
u = &newU
89+
90+
// Path includes the part after the ':'.
91+
u.Path = u.Host[idx+1:] + u.Path
92+
if u.Path[0] != '/' {
93+
u.Path = "/" + u.Path
94+
}
95+
96+
// Host trims up to the :
97+
u.Host = u.Host[:idx]
98+
}
99+
}
100+
81101
// Clone or update the repository
82102
_, err := os.Stat(dst)
83103
if err != nil && !os.IsNotExist(err) {

0 commit comments

Comments
 (0)