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 mod init' error in temp directory is vague #30678

Closed
andrewmed opened this issue Mar 8, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@andrewmed
Copy link

commented Mar 8, 2019

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

$ go version
go version go1.12 linux/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="/home/andy/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/andy/gopath"
GOPROXY=""
GORACE=""
GOROOT="/home/andy/go"
GOTMPDIR=""
GOTOOLDIR="/home/andy/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build556518556=/tmp/go-build -gno-record-gcc-switches"

What did you do?

init go module in git repository

What did you expect to see?

go module initialized

What did you see instead?

go mod does not recognize vcs with three level domains:

andy@debian-dev:/tmp/tmp.dFIHBNexOs$ git init
Initialized empty Git repository in /tmp/tmp.dFIHBNexOs/.git/
andy@debian-dev:/tmp/tmp.dFIHBNexOs$ (master) git remote add origin https://git.bar.com/baz
andy@debian-dev:/tmp/tmp.dFIHBNexOs$ (master) git remote -v
origin  https://git.bar.com/baz (fetch)
origin  https://git.bar.com/baz (push)
andy@debian-dev:/tmp/tmp.dFIHBNexOs$ (master) go mod init
go: cannot determine module path for source directory /tmp/tmp.dFIHBNexOs (outside GOPATH, no import comments)

@andybons andybons changed the title go mod and third level domain problem cmd/go: go mod and third level domain problem Mar 8, 2019

@andybons andybons added this to the Unplanned milestone Mar 8, 2019

@andybons

This comment has been minimized.

Copy link
Member

commented Mar 8, 2019

@jayconrod

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

go mod init can automatically determine the module path (declared in the go.mod file) using either the current directory's position within GOPATH or using import comments in existing source files. Unfortunately, we can't use git remotes because they are frequently different than the module path.

In this example, the directory where go mod init was run is outside GOPATH, and there are no source files, so the module needs to be initialized with an explicit path:

go mod init git.bar.com/baz

We should have a better error message for this though, especially since a lot of people will see this the first time they try modules.

@jayconrod jayconrod modified the milestones: Unplanned, Go1.13 Mar 8, 2019

@jayconrod jayconrod self-assigned this Mar 8, 2019

@andrewmed

This comment has been minimized.

Copy link
Author

commented Mar 8, 2019

I see. I thought it used to pick up a remote from vcs for two level domains O.K., but I can not reproduce this on the latest release branch anymore. So current behavior seems to be consistent for both two and three level domains. Thanks for comment!

@jayconrod

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2019

@andrewmed It looks like it will check if there's a .git/config file with the origin being something at github.com specifically. But it won't try to convert other remotes into a module path, this is just a special case.

@gopherbot

This comment has been minimized.

Copy link

commented Mar 8, 2019

Change https://golang.org/cl/166319 mentions this issue: cmd/go: improve wording of 'go mod init' error

@jayconrod jayconrod changed the title cmd/go: go mod and third level domain problem cmd/go: 'go mod init' error in temp directory is vague Mar 8, 2019

@gopherbot gopherbot closed this in 91c9ed0 Mar 8, 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.