Commit 17ad60b8 authored by Russ Cox's avatar Russ Cox

cmd/go: fix test for moved package in go get -u

What matters during go get -u is not whether there is an import comment
but whether we resolved the path by an HTML <meta> tag.

Fixes #16471.

Change-Id: I6b194a3f73a7962a0170b4d5cf51cfed74e02c00
Reviewed-on: https://go-review.googlesource.com/31658
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarQuentin Smith <quentin@golang.org>
parent f3b4abd8
...@@ -388,7 +388,7 @@ func downloadPackage(p *Package) error { ...@@ -388,7 +388,7 @@ func downloadPackage(p *Package) error {
repo = resolved repo = resolved
} }
} }
if remote != repo && p.ImportComment != "" { if remote != repo && rr.isCustom {
return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote) return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote)
} }
} }
......
...@@ -1180,6 +1180,23 @@ func TestIssue10952(t *testing.T) { ...@@ -1180,6 +1180,23 @@ func TestIssue10952(t *testing.T) {
tg.run("get", "-d", "-u", importPath) tg.run("get", "-d", "-u", importPath)
} }
func TestIssue16471(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("."))
tg.must(os.MkdirAll(tg.path("src/rsc.io/go-get-issue-10952"), 0755))
tg.runGit(tg.path("src/rsc.io"), "clone", "https://github.com/zombiezen/go-get-issue-10952")
tg.runFail("get", "-u", "rsc.io/go-get-issue-10952")
tg.grepStderr("rsc.io/go-get-issue-10952 is a custom import path for https://github.com/rsc/go-get-issue-10952, but .* is checked out from https://github.com/zombiezen/go-get-issue-10952", "did not detect updated import path")
}
// Test git clone URL that uses SCP-like syntax and custom import path checking. // Test git clone URL that uses SCP-like syntax and custom import path checking.
func TestIssue11457(t *testing.T) { func TestIssue11457(t *testing.T) {
testenv.MustHaveExternalNetwork(t) testenv.MustHaveExternalNetwork(t)
......
...@@ -528,6 +528,9 @@ type repoRoot struct { ...@@ -528,6 +528,9 @@ type repoRoot struct {
// root is the import path corresponding to the root of the // root is the import path corresponding to the root of the
// repository // repository
root string root string
// isCustom is true for custom import paths (those defined by HTML meta tags)
isCustom bool
} }
var httpPrefixRE = regexp.MustCompile(`^https?:`) var httpPrefixRE = regexp.MustCompile(`^https?:`)
...@@ -713,9 +716,10 @@ func repoRootForImportDynamic(importPath string, security securityMode) (*repoRo ...@@ -713,9 +716,10 @@ func repoRootForImportDynamic(importPath string, security securityMode) (*repoRo
return nil, fmt.Errorf("%s: invalid repo root %q; no scheme", urlStr, mmi.RepoRoot) return nil, fmt.Errorf("%s: invalid repo root %q; no scheme", urlStr, mmi.RepoRoot)
} }
rr := &repoRoot{ rr := &repoRoot{
vcs: vcsByCmd(mmi.VCS), vcs: vcsByCmd(mmi.VCS),
repo: mmi.RepoRoot, repo: mmi.RepoRoot,
root: mmi.Prefix, root: mmi.Prefix,
isCustom: true,
} }
if rr.vcs == nil { if rr.vcs == nil {
return nil, fmt.Errorf("%s: unknown vcs %q", urlStr, mmi.VCS) return nil, fmt.Errorf("%s: unknown vcs %q", urlStr, mmi.VCS)
......
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