From: Dmitri Shuralyov Date: Thu, 26 May 2016 06:22:11 +0000 (-0700) Subject: cmd/go: fixup for parsing SCP-like addresses X-Git-Tag: go1.7beta1~65 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e9228dd9490c3d4827170abeb8c82e68c175ecf0;p=gostls13.git cmd/go: fixup for parsing SCP-like addresses 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 TryBot-Result: Gobot Gobot Reviewed-by: Andrew Gerrand --- diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 987021ecca..50e6b500da 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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() `) diff --git a/src/cmd/go/vcs.go b/src/cmd/go/vcs.go index 3b6e08f155..10b8cf8c49 100644 --- a/src/cmd/go/vcs.go +++ b/src/cmd/go/vcs.go @@ -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)