Skip to content
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` creates go.mod and go.sum files inconsistently, depending on directory #30248

Closed
douglarek opened this issue Feb 15, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@douglarek
Copy link

commented Feb 15, 2019

What version of Go are you using (go version)?

~ $ go version
go version go1.12rc1 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lingchax/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lingchax/.go"
GOPROXY="https://athens.azurefd.net/"
GORACE=""
GOROOT="/Users/lingchax/sdk/go1.12rc1"
GOTMPDIR=""
GOTOOLDIR="/Users/lingchax/sdk/go1.12rc1/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/pq/lsz6sm8956vfcgd42rk4rfn00000gn/T/go-build922124980=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ export GO111MODULE=on
$ go get -x github.com/saibing/bingo

What did you expect to see?

github.com/saibing/bingo should be installed as bingo to $GOPATH/bin/ without creating go.mod and go.sum.

What did you see instead?

When I run it in a git repo, it will create go.mod and go.sum:

~/.g/s/g/s/gocode (master|✔) $ go get -x github.com/saibing/bingo
go: creating new go.mod: module github.com/stamblerre/gocode
WORK=/var/folders/pq/lsz6sm8956vfcgd42rk4rfn00000gn/T/go-build121973882

but when I run it in a non-git directory:

~ $ go get -x github.com/saibing/bingo
WORK=/var/folders/pq/lsz6sm8956vfcgd42rk4rfn00000gn/T/go-build044041777

It is very confusing.

@katiehockman katiehockman changed the title cmd/go: inconsistent behavior when use `go get` to install a gomod binary with GO111MODULE on in different directories cmd/go: `go get` creates go.mod and go.sum files inconsistently, depending on directory Feb 15, 2019

@katiehockman

This comment has been minimized.

Copy link
Contributor

commented Feb 15, 2019

I think this is expected behavior for the go command running in modules mode. The go command documentation for module downloading and verification describes this - namely that it creates a go.mod and go.sum in the main module's root directory, and will be updated/created when a new dependency is installed. I don't think it has anything to do with being in a git repository specifically, but being in a directory that contains go code.

This also may be a more appropriate question to post at https://golang.org/wiki/Questions.

/cc @bcmills to correct me or add extra context.

@katiehockman katiehockman added this to the Unplanned milestone Feb 15, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Feb 15, 2019

Dup of #29433, for which I've just submitted a (partial) fix.

(The remaining work for that is to make go mod init choose the correct module path for repos with v2+ tags.)

@bcmills bcmills closed this Feb 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.