]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fixup for parsing SCP-like addresses
authorDmitri Shuralyov <shurcooL@gmail.com>
Thu, 26 May 2016 06:22:11 +0000 (23:22 -0700)
committerAndrew Gerrand <adg@golang.org>
Fri, 27 May 2016 06:28:40 +0000 (06:28 +0000)
This is a fixup change for commit 5cd294480364eb166751838a3df8f58649c214e1
that added parsing of SCP-like addresses. To get the expected output
from (*url.URL).String(), Path needs to be set, not RawPath.

Add a test for this, since it has already regressed multiple times.

Updates #11457.

Change-Id: I806f5abbd3cf65e5bdcef01aab872caa8a5b8891
Reviewed-on: https://go-review.googlesource.com/23447
Run-TryBot: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/go/go_test.go
src/cmd/go/vcs.go

index 987021ecca97b05d809f4954ed02a818bc895cd3..50e6b500dab3d781877568bbac62d1c81d927b80 100644 (file)
@@ -1151,7 +1151,7 @@ func TestImportCommentConflict(t *testing.T) {
        tg.grepStderr("found import comments", "go build did not mention comment conflict")
 }
 
-// cmd/go: custom import path checking should not apply to github.com/xxx/yyy.
+// cmd/go: custom import path checking should not apply to Go packages without import comment.
 func TestIssue10952(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
        if _, err := exec.LookPath("git"); err != nil {
@@ -1170,6 +1170,34 @@ func TestIssue10952(t *testing.T) {
        tg.run("get", "-d", "-u", importPath)
 }
 
+// Test git clone URL that uses SCP-like syntax and custom import path checking.
+func TestIssue11457(t *testing.T) {
+       testenv.MustHaveExternalNetwork(t)
+       if _, err := exec.LookPath("git"); err != nil {
+               t.Skip("skipping because git binary not found")
+       }
+
+       tg := testgo(t)
+       defer tg.cleanup()
+       tg.parallel()
+       tg.tempDir("src")
+       tg.setenv("GOPATH", tg.path("."))
+       const importPath = "github.com/rsc/go-get-issue-11457"
+       tg.run("get", "-d", "-u", importPath)
+       repoDir := tg.path("src/" + importPath)
+       tg.runGit(repoDir, "remote", "set-url", "origin", "git@github.com:rsc/go-get-issue-11457")
+
+       // At this time, custom import path checking compares remotes verbatim (rather than
+       // just the host and path, skipping scheme and user), so we expect go get -u to fail.
+       // However, the goal of this test is to verify that gitRemoteRepo correctly parsed
+       // the SCP-like syntax, and we expect it to appear in the error message.
+       tg.runFail("get", "-d", "-u", importPath)
+       want := " is checked out from ssh://git@github.com/rsc/go-get-issue-11457"
+       if !strings.HasSuffix(strings.TrimSpace(tg.getStderr()), want) {
+               t.Error("expected clone URL to appear in stderr")
+       }
+}
+
 func TestGetGitDefaultBranch(t *testing.T) {
        testenv.MustHaveExternalNetwork(t)
        if _, err := exec.LookPath("git"); err != nil {
@@ -2814,7 +2842,7 @@ func TestBinaryOnlyPackages(t *testing.T) {
        tg.grepStderr("no buildable Go source files", "did not complain about missing sources")
 
        tg.tempFile("src/p1/missing.go", `//go:binary-only-package
-       
+
                package p1
                func G()
        `)
index 3b6e08f155b0e03c02ef539f53c766823abb424e..10b8cf8c49dcfa39b446c52b01d403d86f611489 100644 (file)
@@ -171,10 +171,10 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error
                // 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],
+                       Scheme: "ssh",
+                       User:   url.User(m[1]),
+                       Host:   m[2],
+                       Path:   m[3],
                }
        } else {
                repoURL, err = url.Parse(out)