]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: allow omitted user name in git ssh repo syntax
authorRuss Cox <rsc@golang.org>
Thu, 17 Dec 2015 06:41:15 +0000 (01:41 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 17 Dec 2015 17:01:05 +0000 (17:01 +0000)
No test because the code has no test.

Fixes #12313.

Change-Id: I2cfd0a0422c0cd76f0371c2d3bbbdf5bb3b3f1eb
Reviewed-on: https://go-review.googlesource.com/17951
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/vcs.go

index a1100960bffe6fb0b76aff79732a019f43a99ed7..316a7ec79d8801bd9cf942f04e7f10237df04fe7 100644 (file)
@@ -147,7 +147,7 @@ var vcsGit = &vcsCmd{
 
 // 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._-]+):(.*)$`)
+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"
@@ -171,10 +171,12 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error
                // "ssh://git@github.com/user/repo".
                repoURL = &url.URL{
                        Scheme:  "ssh",
-                       User:    url.User(m[1]),
                        Host:    m[2],
                        RawPath: m[3],
                }
+               if m[1] != "" {
+                       repoURL.User = url.User(m[1])
+               }
        } else {
                repoURL, err = url.Parse(out)
                if err != nil {