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 return error if there is no func main() in the current working directory #52179

Closed
ansidev opened this issue Apr 6, 2022 · 3 comments

Comments

@ansidev
Copy link

ansidev commented Apr 6, 2022

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

go version go1.18 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

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="{secret}"
GOENV="{secret}"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="{secret}"
GONOPROXY="{secret}"
GONOSUMDB="{secret}"
GOOS="darwin"
GOPATH="/Users/mac/go"
GOPRIVATE="{secret}"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.18/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK="{secret}"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rg/2ghbpv594593xwc66z446w5w0000gn/T/go-build2275001121=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run the following commands:

$ git clone https://github.com/ansidev/go-get-issue
$ git checkout failed
$ ls -la

total 24
drwxr-xr-x   6 user  staff   192 Apr  6 17:36 .
drwxr-xr-x@ 40 user  staff  1280 Apr  6 17:25 ..
drwxr-xr-x  12 user  staff   384 Apr  6 17:36 .git
-rw-r--r--   1 user  staff   165 Apr  6 17:36 go.mod
-rw-r--r--   1 user  staff  5352 Apr  6 17:36 go.sum
drwxr-xr-x   3 user  staff    96 Apr  6 16:51 log

$ go get -u
go: no package to get in current directory
$ git checkout work
$ go get -u
go: upgraded go.uber.org/atomic v1.7.0 => v1.9.0
go: upgraded go.uber.org/multierr v1.6.0 => v1.8.0
go: upgraded go.uber.org/zap v1.20.0 => v1.21.0
(dependencies should be upgraded because the current version is outdated)

What did you expect to see?

Run go get -u on branch failed should upgrade dependencies.
In the past, it worked. I'm don't know the go version exactly, maybe 1.16 or 1.17.

What did you see instead?

go: no package to get in current directory

@seankhliao
Copy link
Member

This hasn't worked since 1.13, and the bahaviour is consistent with the help text:

The -u flag instructs get to update modules providing dependencies
of packages named on the command line

you probably want the ./... pattern

For questions please refer to https://github.com/golang/go/wiki/Questions

@jiangbajin

This comment was marked as spam.

@ansidev
Copy link
Author

ansidev commented Apr 6, 2022

@seankhliao I got it. This is my mistake. But I believe that adding a meaningful message is a better choice and it will help developers save time to debug this issue. For example:

Did you mean that `go get -u ./...`?

Or something like that.
Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants