]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/get: fix "mod over non-mod" preference for meta tags
authorRuss Cox <rsc@golang.org>
Wed, 18 Jul 2018 19:45:13 +0000 (15:45 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 19 Jul 2018 18:44:09 +0000 (18:44 +0000)
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>
src/cmd/go/internal/get/pkg_test.go
src/cmd/go/internal/get/vcs.go
src/cmd/go/internal/get/vcs_test.go

index 2f61365090e75faff3ab1a9931c8ee98eb9ecb5d..fc6a179c2e1f0b9d6fe112d1682cf437b4578341 100644 (file)
@@ -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) {
index 82392d307b36a8331deee35dc6e98b0c36b964ac..a4fd28e2a48e0c3f0b60901bd33ba8a8c7a2c988 100644 (file)
@@ -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
index 142701a70a38f277919685eddd4109715ed291c3..d13721bed1a489b3ab974c364b4cef6d6e79a0f9 100644 (file)
@@ -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 {