aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2018-07-18 15:45:13 -0400
committerRuss Cox <rsc@golang.org>2018-07-19 18:44:09 +0000
commitceca60228205652c0791d649368dd8e550073810 (patch)
tree8e19ffb95c98e4536428701ec9ca76ecfa292aea
parentff81a6444a9171ffe3021353388047a698b21252 (diff)
downloadgo-ceca60228205652c0791d649368dd8e550073810.tar.gz
go-ceca60228205652c0791d649368dd8e550073810.zip
cmd/go/internal/get: fix "mod over non-mod" preference for meta tags
If there was a mod and non-mod meta tag for a given prefix, the meta tag extractor was already dropping the non-mod meta tag. But we might have mod and non-mod meta tags with different prefixes, in which case the mod tag should prevail when both match. Fixes #26200. Change-Id: I17ab361338e270b9fa03999ad1954f2bbe0f5017 Reviewed-on: https://go-review.googlesource.com/124714 Reviewed-by: Bryan C. Mills <bcmills@google.com>
-rw-r--r--src/cmd/go/internal/get/pkg_test.go17
-rw-r--r--src/cmd/go/internal/get/vcs.go8
-rw-r--r--src/cmd/go/internal/get/vcs_test.go16
3 files changed, 40 insertions, 1 deletions
diff --git a/src/cmd/go/internal/get/pkg_test.go b/src/cmd/go/internal/get/pkg_test.go
index 2f61365090..fc6a179c2e 100644
--- a/src/cmd/go/internal/get/pkg_test.go
+++ b/src/cmd/go/internal/get/pkg_test.go
@@ -98,6 +98,23 @@ var parseMetaGoImportsTests = []struct {
IgnoreMod,
[]metaImport{{"chitin.io/chitin", "git", "https://github.com/chitin-io/chitin"}},
},
+ {
+ `<meta name="go-import" content="myitcv.io git https://github.com/myitcv/x">
+ <meta name="go-import" content="myitcv.io/blah2 mod https://raw.githubusercontent.com/myitcv/pubx/master">
+ `,
+ IgnoreMod,
+ []metaImport{{"myitcv.io", "git", "https://github.com/myitcv/x"}},
+ },
+ {
+ `<meta name="go-import" content="myitcv.io git https://github.com/myitcv/x">
+ <meta name="go-import" content="myitcv.io/blah2 mod https://raw.githubusercontent.com/myitcv/pubx/master">
+ `,
+ PreferMod,
+ []metaImport{
+ {"myitcv.io/blah2", "mod", "https://raw.githubusercontent.com/myitcv/pubx/master"},
+ {"myitcv.io", "git", "https://github.com/myitcv/x"},
+ },
+ },
}
func TestParseMetaGoImports(t *testing.T) {
diff --git a/src/cmd/go/internal/get/vcs.go b/src/cmd/go/internal/get/vcs.go
index 82392d307b..a4fd28e2a4 100644
--- a/src/cmd/go/internal/get/vcs.go
+++ b/src/cmd/go/internal/get/vcs.go
@@ -948,7 +948,13 @@ func matchGoImport(imports []metaImport, importPath string) (metaImport, error)
continue
}
- if match != -1 {
+ if match >= 0 {
+ if imports[match].VCS == "mod" && im.VCS != "mod" {
+ // All the mod entries precede all the non-mod entries.
+ // We have a mod entry and don't care about the rest,
+ // matching or not.
+ break
+ }
return metaImport{}, fmt.Errorf("multiple meta tags match import path %q", importPath)
}
match = i
diff --git a/src/cmd/go/internal/get/vcs_test.go b/src/cmd/go/internal/get/vcs_test.go
index 142701a70a..d13721bed1 100644
--- a/src/cmd/go/internal/get/vcs_test.go
+++ b/src/cmd/go/internal/get/vcs_test.go
@@ -401,6 +401,22 @@ func TestMatchGoImport(t *testing.T) {
path: "different.example.com/user/foo",
err: errors.New("meta tags do not match import path"),
},
+ {
+ imports: []metaImport{
+ {Prefix: "myitcv.io/blah2", VCS: "mod", RepoRoot: "https://raw.githubusercontent.com/myitcv/pubx/master"},
+ {Prefix: "myitcv.io", VCS: "git", RepoRoot: "https://github.com/myitcv/x"},
+ },
+ path: "myitcv.io/blah2/foo",
+ mi: metaImport{Prefix: "myitcv.io/blah2", VCS: "mod", RepoRoot: "https://raw.githubusercontent.com/myitcv/pubx/master"},
+ },
+ {
+ imports: []metaImport{
+ {Prefix: "myitcv.io/blah2", VCS: "mod", RepoRoot: "https://raw.githubusercontent.com/myitcv/pubx/master"},
+ {Prefix: "myitcv.io", VCS: "git", RepoRoot: "https://github.com/myitcv/x"},
+ },
+ path: "myitcv.io/other",
+ mi: metaImport{Prefix: "myitcv.io", VCS: "git", RepoRoot: "https://github.com/myitcv/x"},
+ },
}
for _, test := range tests {