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 $module@$commit should resolve it to the highest appropriate pseudo-version #27171

Open
rogpeppe opened this Issue Aug 23, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@rogpeppe
Contributor

rogpeppe commented Aug 23, 2018

go version go1.11rc2 linux/amd64

With my existing $GOPATH, I can run go get to get a particular commit, and it doesn't use the correct version as I'd expect from https://go-review.googlesource.com/c/go/+/124515, but downgrades instead. With a fresh $GOPATH, it works OK, so I suspect that somehow the cached info isn't being updated appropriately.

Here's what I did:

% cd /tmp
% mkdir modtest
% cd modtest
% go mod init example.com/foo/bar
go: creating new go.mod: module example.com/foo/bar
% cat > main.go
package main
import _ "github.com/frankban/quicktest"

func main() {
}
% go mod tidy
% go list -m all | grep cmp
github.com/google/go-cmp v0.2.0
% go get -x github.com/google/go-cmp@5411ab924f9ffa6566244a9e504bc347edacffd3
# /home/rog/src/go/pkg/mod/cache/vcs/bf8dbe084a71342417894c38c6144465bdc383bd4eb51954ad4212efcf8a7445 for git2 https://github.com/frankban/quicktest
cd /home/rog/src/go/pkg/mod/cache/vcs/bf8dbe084a71342417894c38c6144465bdc383bd4eb51954ad4212efcf8a7445; git ls-remote -q https://github.com/frankban/quicktest
1.303s # cd /home/rog/src/go/pkg/mod/cache/vcs/bf8dbe084a71342417894c38c6144465bdc383bd4eb51954ad4212efcf8a7445; git ls-remote -q https://github.com/frankban/quicktest
# /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e for git2 https://github.com/google/go-cmp
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git ls-remote -q https://github.com/google/go-cmp
1.243s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git ls-remote -q https://github.com/google/go-cmp
% cat go.mod
module example.com/foo/bar

require (
	github.com/frankban/quicktest v0.8.0
	github.com/google/go-cmp v0.0.0-20180328201512-5411ab924f9f // indirect
	github.com/kr/pretty v0.1.0 // indirect
)
% 

Note that despite getting the latest master commit of go-cmp, it has downgraded the quicktest package inappropriately, and at no point did it run the git describe command which would have told it which version to use. If I use @master, it works correctly:

% GOPATH=$h/src/go
% echo module example.com/foo/bar > go.mod
% go mod tidy
% cat go.mod
module example.com/foo/bar

require github.com/frankban/quicktest v1.1.0
% go get -x github.com/google/go-cmp@master
# /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e for git2 https://github.com/google/go-cmp
go: finding github.com/google/go-cmp master
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git tag -l
0.004s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git tag -l
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git ls-remote -q https://github.com/google/go-cmp
1.300s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git ls-remote -q https://github.com/google/go-cmp
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
0.004s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
0.005s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
0.007s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git describe --first-parent --always --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' --tags 5411ab924f9ffa6566244a9e504bc347edacffd3
0.007s # cd /home/rog/src/go/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git describe --first-parent --always --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' --tags 5411ab924f9ffa6566244a9e504bc347edacffd3
% cat go.mod
module example.com/foo/bar

require (
	github.com/frankban/quicktest v1.1.0
	github.com/google/go-cmp v0.2.1-0.20180328201512-5411ab924f9f // indirect
)

If I use a fresh $GOPATH, it also works OK:

% echo module example.com/foo/bar > go.mod
% go mod tidy
go: finding github.com/frankban/quicktest v1.1.0
go: downloading github.com/frankban/quicktest v1.1.0
go: finding github.com/google/go-cmp v0.2.0
go: finding github.com/kr/pretty v0.1.0
go: finding github.com/kr/text v0.1.0
go: finding github.com/kr/pty v1.1.1
go: downloading github.com/google/go-cmp v0.2.0
go: downloading github.com/kr/pretty v0.1.0
go: downloading github.com/kr/text v0.1.0
% cat go.mod
module example.com/foo/bar

require github.com/frankban/quicktest v1.1.0
% go list -m all | grep cmp
github.com/google/go-cmp v0.2.0
% go get -x github.com/google/go-cmp@5411ab924f9ffa6566244a9e504bc347edacffd3
# /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e for git2 https://github.com/google/go-cmp
go: finding github.com/google/go-cmp 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
0.003s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git tag -l
0.002s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git tag -l
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git ls-remote -q https://github.com/google/go-cmp
1.328s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git ls-remote -q https://github.com/google/go-cmp
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git fetch -f --depth=1 https://github.com/google/go-cmp 5411ab924f9ffa6566244a9e504bc347edacffd3:refs/dummy
1.477s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git fetch -f --depth=1 https://github.com/google/go-cmp 5411ab924f9ffa6566244a9e504bc347edacffd3:refs/dummy
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
0.002s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
0.002s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git describe --first-parent --always --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' --tags 5411ab924f9ffa6566244a9e504bc347edacffd3
0.002s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git describe --first-parent --always --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' --tags 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c protocol.version=0 fetch --unshallow -f https://github.com/google/go-cmp 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
1.729s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c protocol.version=0 fetch --unshallow -f https://github.com/google/go-cmp 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git describe --first-parent --always --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' --tags 5411ab924f9ffa6566244a9e504bc347edacffd3
0.014s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git describe --first-parent --always --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' --tags 5411ab924f9ffa6566244a9e504bc347edacffd3
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9f
0.006s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c log.showsignature=false log -n1 '--format=format:%H %ct %D' 5411ab924f9f
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
0.004s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
0.003s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
go: downloading github.com/google/go-cmp v0.2.1-0.20180328201512-5411ab924f9f
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
0.002s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git cat-file blob 5411ab924f9ffa6566244a9e504bc347edacffd3:go.mod
cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 5411ab924f9ffa6566244a9e504bc347edacffd3
0.018s # cd /tmp/gomodtestpath/pkg/mod/cache/vcs/e5e4370a1db1bf6e0ffae53084bf5ba02ef21c66da499923d373134469cb366e; git -c core.autocrlf=input -c core.eol=lf archive --format=zip --prefix=prefix/ 5411ab924f9ffa6566244a9e504bc347edacffd3
% 
% cat go.mod
module example.com/foo/bar

require (
	github.com/frankban/quicktest v1.1.0
	github.com/google/go-cmp v0.2.1-0.20180328201512-5411ab924f9f // indirect
)

@rogpeppe rogpeppe added the modules label Aug 23, 2018

@bcmills bcmills added this to the Go1.12 milestone Nov 16, 2018

@bcmills

This comment has been minimized.

Member

bcmills commented Nov 16, 2018

github.com/google/go-cmp v0.0.0-20180328201512-5411ab924f9f // indirect

The v0.0.0 pseudo-version is the problem: go get sees that and decides that it needs to downgrade quicktest, because the previous quicktest version required v0.2.0.

I don't know how you got an entry mapping that commit to v0.0.0 in your module cache, given that it's after the v0.2.0 tag, but I'm not surprised: we are a bit sloppy about the pseudo-versions we allow (#27173). Perhaps you resolved it as v0.0.0 via an older go.mod file at some point?

At any rate, if you go get the go-cmp repo with a higher-numbered pseudoversion, you'll find that it sticks:

go: creating new go.mod: module golang.org/issue/27171

$ go get -m github.com/google/go-cmp@v0.0.0-20180328201512-5411ab924f9f
go: finding github.com/google/go-cmp v0.0.0-20180328201512-5411ab924f9f

$ go get -m github.com/frankban/quicktest@v1.1.0
go: finding github.com/frankban/quicktest v1.1.0
go: finding github.com/google/go-cmp v0.2.0
go: finding github.com/kr/pretty v0.1.0
go: finding github.com/kr/text v0.1.0
go: finding github.com/kr/pty v1.1.1

$ go list -m all
golang.org/issue/27171
github.com/frankban/quicktest v1.1.0
github.com/google/go-cmp v0.2.0
github.com/kr/pretty v0.1.0
github.com/kr/pty v1.1.1
github.com/kr/text v0.1.0

$ go get -m github.com/google/go-cmp@5411ab924f9f
go: finding github.com/frankban/quicktest v1.0.0
go: finding github.com/frankban/quicktest v0.9.1
go: finding github.com/frankban/quicktest v0.9.0
go: finding github.com/frankban/quicktest v0.8.0

$ go list -m all
golang.org/issue/27171
github.com/frankban/quicktest v0.8.0
github.com/google/go-cmp v0.0.0-20180328201512-5411ab924f9f
github.com/kr/pretty v0.1.0
github.com/kr/pty v1.1.1
github.com/kr/text v0.1.0

$ go get -m github.com/google/go-cmp@v0.2.1-0.20180328201512-5411ab924f9f
go: finding github.com/google/go-cmp v0.2.1-0.20180328201512-5411ab924f9f

$ go get -m github.com/frankban/quicktest@v1.1.0

$ go get -m github.com/google/go-cmp@5411ab924f9f

$ go list -m all
golang.org/issue/27171
github.com/frankban/quicktest v1.1.0
github.com/google/go-cmp v0.2.1-0.20180328201512-5411ab924f9f
github.com/kr/pretty v0.1.0
github.com/kr/pty v1.1.1
github.com/kr/text v0.1.0

@bcmills bcmills changed the title from cmd/go: go get $module@$commit sometimes downgrades inappropriately to cmd/go: go get $module@$commit should resolve it to the highest appropriate pseudo-version Nov 16, 2018

@bcmills bcmills modified the milestones: Go1.12, Go1.13 Nov 16, 2018

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