From 7fa96f08a4b11d710c8b1cb0d8f29e131e1793db Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 26 Sep 2014 12:09:27 -0400 Subject: [PATCH] cmd/go: fix 'go get vanity/repo/...' in clean GOPATH The pattern was only working if the checkout had already been done, but the code was trying to make it work even the first time. Test and fix. Fixes #8335. LGTM=r R=golang-codereviews, r CC=golang-codereviews, iant https://golang.org/cl/146310043 --- src/cmd/go/test.bash | 12 ++++++++++++ src/cmd/go/vcs.go | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash index 8bd01ea21b..5e4e43722a 100755 --- a/src/cmd/go/test.bash +++ b/src/cmd/go/test.bash @@ -948,6 +948,18 @@ elif ! grep "$GOARCH test3.go p xyzp/test3.go/123" testdata/std.out > /dev/null; ok=false fi +TEST go get works with vanity wildcards +d=$(mktemp -d -t testgoXXX) +export GOPATH=$d +if ! ./testgo get -u rsc.io/pdf/...; then + ok=false +elif [ ! -x $d/bin/pdfpasswd ]; then + echo did not build rsc.io/pdf/pdfpasswd + ok=false +fi +unset GOPATH +rm -rf $d + # clean up if $started; then stop; fi rm -rf testdata/bin testdata/bin1 diff --git a/src/cmd/go/vcs.go b/src/cmd/go/vcs.go index d07948e64c..c5d246835d 100644 --- a/src/cmd/go/vcs.go +++ b/src/cmd/go/vcs.go @@ -361,7 +361,14 @@ var httpPrefixRE = regexp.MustCompile(`^https?:`) func repoRootForImportPath(importPath string) (*repoRoot, error) { rr, err := repoRootForImportPathStatic(importPath, "") if err == errUnknownSite { - rr, err = repoRootForImportDynamic(importPath) + // If there are wildcards, look up the thing before the wildcard, + // hoping it applies to the wildcarded parts too. + // This makes 'go get rsc.io/pdf/...' work in a fresh GOPATH. + lookup := strings.TrimSuffix(importPath, "/...") + if i := strings.Index(lookup, "/.../"); i >= 0 { + lookup = lookup[:i] + } + rr, err = repoRootForImportDynamic(lookup) // repoRootForImportDynamic returns error detail // that is irrelevant if the user didn't intend to use a -- 2.48.1