Commit 3e9f0636 authored by Russ Cox's avatar Russ Cox

cmd/go: allow omitted user name in git ssh repo syntax

No test because the code has no test.

Fixes #12313.

Change-Id: I2cfd0a0422c0cd76f0371c2d3bbbdf5bb3b3f1eb
Reviewed-on: https://go-review.googlesource.com/17951Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent f9137c53
...@@ -147,7 +147,7 @@ var vcsGit = &vcsCmd{ ...@@ -147,7 +147,7 @@ var vcsGit = &vcsCmd{
// scpSyntaxRe matches the SCP-like addresses used by Git to access // scpSyntaxRe matches the SCP-like addresses used by Git to access
// repositories by SSH. // repositories by SSH.
var scpSyntaxRe = regexp.MustCompile(`^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.*)$`) var scpSyntaxRe = regexp.MustCompile(`^(?:([a-zA-Z0-9_]+)@)?([a-zA-Z0-9._-]+):(.*)$`)
func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) { func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error) {
cmd := "config remote.origin.url" cmd := "config remote.origin.url"
...@@ -171,10 +171,12 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error ...@@ -171,10 +171,12 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error
// "ssh://git@github.com/user/repo". // "ssh://git@github.com/user/repo".
repoURL = &url.URL{ repoURL = &url.URL{
Scheme: "ssh", Scheme: "ssh",
User: url.User(m[1]),
Host: m[2], Host: m[2],
RawPath: m[3], RawPath: m[3],
} }
if m[1] != "" {
repoURL.User = url.User(m[1])
}
} else { } else {
repoURL, err = url.Parse(out) repoURL, err = url.Parse(out)
if err != nil { if err != nil {
......
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