Commit 5cd29448 authored by Andrew Gerrand's avatar Andrew Gerrand

cmd/go: fix parsing of Git SCP-like remotes

Now that we care about the protocol of Git remotes (for the -insecure
flag), we need to recognize and parse the SCP-like remote format.

Fixes golang/go#11457

Change-Id: Ia26132274fafb1cbfefe2475f7ac5f17ccd6da40
Reviewed-on: https://go-review.googlesource.com/12226Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent e42413ce
......@@ -140,11 +140,15 @@ var vcsGit = &vcsCmd{
// See golang.org/issue/9032.
tagSyncDefault: []string{"checkout master", "submodule update --init --recursive"},
scheme: []string{"git", "https", "http", "git+ssh"},
scheme: []string{"git", "https", "http", "git+ssh", "ssh"},
pingCmd: "ls-remote {scheme}://{repo}",
remoteRepo: gitRemoteRepo,
}
// scpSyntaxRe matches the SCP-like addresses used by Git to access
// repositories by SSH.
var scpSyntaxRe = regexp.MustCompile(`^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.*)$`)
func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) {
cmd := "config remote.origin.url"
errParse := errors.New("unable to parse output of git " + cmd)
......@@ -158,9 +162,24 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error
}
return "", err
}
repoURL, err := url.Parse(strings.TrimSpace(string(outb)))
if err != nil {
return "", err
out := strings.TrimSpace(string(outb))
var repoURL *url.URL
if m := scpSyntaxRe.FindStringSubmatch(out); m != nil {
// Match SCP-like syntax and convert it to a URL.
// Eg, "git@github.com:user/repo" becomes
// "ssh://git@github.com/user/repo".
repoURL = &url.URL{
Scheme: "ssh",
User: url.User(m[1]),
Host: m[2],
RawPath: m[3],
}
} else {
repoURL, err = url.Parse(out)
if err != nil {
return "", err
}
}
// Iterate over insecure schemes too, because this function simply
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment