Commit e9228dd9 authored by Dmitri Shuralyov's avatar Dmitri Shuralyov Committed by Andrew Gerrand

cmd/go: fixup for parsing SCP-like addresses

This is a fixup change for commit 5cd29448
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: default avatarAndrew Gerrand <adg@golang.org>
parent 20803b84
...@@ -1151,7 +1151,7 @@ func TestImportCommentConflict(t *testing.T) { ...@@ -1151,7 +1151,7 @@ func TestImportCommentConflict(t *testing.T) {
tg.grepStderr("found import comments", "go build did not mention comment conflict") 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) { func TestIssue10952(t *testing.T) {
testenv.MustHaveExternalNetwork(t) testenv.MustHaveExternalNetwork(t)
if _, err := exec.LookPath("git"); err != nil { if _, err := exec.LookPath("git"); err != nil {
...@@ -1170,6 +1170,34 @@ func TestIssue10952(t *testing.T) { ...@@ -1170,6 +1170,34 @@ func TestIssue10952(t *testing.T) {
tg.run("get", "-d", "-u", importPath) 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) { func TestGetGitDefaultBranch(t *testing.T) {
testenv.MustHaveExternalNetwork(t) testenv.MustHaveExternalNetwork(t)
if _, err := exec.LookPath("git"); err != nil { if _, err := exec.LookPath("git"); err != nil {
...@@ -2814,7 +2842,7 @@ func TestBinaryOnlyPackages(t *testing.T) { ...@@ -2814,7 +2842,7 @@ func TestBinaryOnlyPackages(t *testing.T) {
tg.grepStderr("no buildable Go source files", "did not complain about missing sources") tg.grepStderr("no buildable Go source files", "did not complain about missing sources")
tg.tempFile("src/p1/missing.go", `//go:binary-only-package tg.tempFile("src/p1/missing.go", `//go:binary-only-package
package p1 package p1
func G() func G()
`) `)
......
...@@ -171,10 +171,10 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error ...@@ -171,10 +171,10 @@ func gitRemoteRepo(vcsGit *vcsCmd, rootDir string) (remoteRepo string, err error
// Eg, "git@github.com:user/repo" becomes // Eg, "git@github.com:user/repo" becomes
// "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]), User: url.User(m[1]),
Host: m[2], Host: m[2],
RawPath: m[3], Path: m[3],
} }
} else { } else {
repoURL, err = url.Parse(out) repoURL, err = url.Parse(out)
......
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