New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go get with ... fails in module mode #29363

Open
rsc opened this Issue Dec 20, 2018 · 4 comments

Comments

Projects
None yet
6 participants
@rsc
Copy link
Contributor

rsc commented Dec 20, 2018

This used to work and should ideally keep working.

$ go get -u github.com/google/codesearch/cmd/...
go: finding github.com/google/codesearch/cmd/... latest
go: finding github.com/google/codesearch/cmd latest
go: finding github.com/google/codesearch latest
go: downloading github.com/google/codesearch v0.0.0-20150617151851-a45d81b686e8
go: extracting github.com/google/codesearch v0.0.0-20150617151851-a45d81b686e8
go get github.com/google/codesearch/cmd/...: no matching versions for query "latest"
$ go list github.com/google/codesearch/...
go: warning: "github.com/google/codesearch/..." matched no packages

@rsc rsc added this to the Go1.13 milestone Dec 20, 2018

@thepudds

This comment has been minimized.

Copy link

thepudds commented Dec 27, 2018

There might be some overlap with #27215 (including #27215 (comment), which describes how the documentation uses go get golang.org/x/perf/cmd/..., but that example fails, unless you have first done something like go get golang.org/x/perf/cmd/benchstat).

@hxzhao527

This comment has been minimized.

Copy link

hxzhao527 commented Jan 7, 2019

I think this caued by this

haveGoFiles = haveGoFilesCache.Do(dir, func() interface{} {
f, err := os.Open(dir)
if err != nil {
return false
}
defer f.Close()
names, _ := f.Readdirnames(-1)
for _, name := range names {
if strings.HasSuffix(name, ".go") {
info, err := os.Stat(filepath.Join(dir, name))
if err == nil && info.Mode().IsRegular() {
return true
}
}
}
return false
}).(bool)

when go get -u github.com/google/codesearch/cmd/..., dir is $GOPATH/pkg/mod/github.com/google/codesearch@v1.1.0/cmd/.... So os.Open will return error. And then no go source be throwed and get failed with not found.

I just motify this func to this:

haveGoFiles = haveGoFilesCache.Do(dir, func() interface{} {
		if strings.HasSuffix(dir, "/..."){
			dir = strings.TrimSuffix(dir, "/...")
			tmp, err := filepath.Glob(dir+"/**/*.go")
			if err != nil{
				return false
			}
			return len(tmp) > 0
		}
		f, err := os.Open(dir)
                ...

I did little test, to get

golang.org/x/tools/...
github.com/google/codesearch/cmd/...

And it works.

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Jan 8, 2019

Change https://golang.org/cl/156757 mentions this issue: cmd/go: fix go get with ... fails in module mode

@mvdan

This comment has been minimized.

Copy link
Member

mvdan commented Jan 19, 2019

@bcmills any chance this could be fixed in 1.12, or backported into a 1.12.x release at a later time?

It's great that with https://go-review.googlesource.com/c/go/+/148517, one can tell a program's users to install a specific version easily via GO111MODULE=on go get foo.com/bar@v1.2.3. However, it's a shame that GO111MODULE=on go get foo.com/bar/cmd/...@v1.2.3 doesn't work.

I realise the plan is to fix it in 1.13, but that would mean easy install instructions would be delayed by six months, as one can't expect users to run on betas or master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment