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: fmt always attempts to update module cache #30577

Closed
driusan opened this issue Mar 4, 2019 · 3 comments
Closed

cmd/go: fmt always attempts to update module cache #30577

driusan opened this issue Mar 4, 2019 · 3 comments

Comments

@driusan
Copy link

driusan commented Mar 4, 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/driusan/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/driusan/go"
GOPROXY=""
GORACE=""
GOROOT="/home/driusan/go1.12"
GOTMPDIR=""
GOTOOLDIR="/home/driusan/go1.12/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/driusan/Code/tst/go.mod"
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-build265641249=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Inside of a go module, run go fmt -x

What did you expect to see?

Invocations of gofmt to format the code.

What did you see instead?

Invocations of git to attempt to update the dependency modules. go fmt appears to always update imported modules with git, and does not have any way to only autoformat the local files.

Other go commands such as build or install can avoid the git overhead with -mod vendor, but fmt doesn't support the -mod argument. As a result packages which are fully vendored can be built, but not formatted without a working internet connection and/or git client.

@mvdan mvdan added the modules label Mar 5, 2019
@mvdan mvdan changed the title go fmt always attempts to update module cache cmd/go: fmt always attempts to update module cache Mar 5, 2019
@mvdan
Copy link
Member

mvdan commented Mar 5, 2019

/cc @bcmills for the modules question.

As an aside, have you considered using gofmt instead? It's a lower-level tool that works on files and directories; go fmt calls it under the hood. It doesn't understand package patterns like ./... or foo.com/bar, but usually a developer is formatting code near the current directory.

This is not to say that gofmt is a better tool, but if you want to format files without ever touching the module cache, it seems like the right tool for you.

@bcmills
Copy link
Contributor

bcmills commented Mar 5, 2019

fmt doesn't support the -mod argument

Yep. And that makes this a duplicate of #27841.

@bcmills bcmills closed this as completed Mar 5, 2019
@driusan
Copy link
Author

driusan commented Mar 5, 2019

@mvdan I'm using gofmt on individual files by necessity for now (this came up in the context of trying to bootstrap go module's git requirements into github.com/driusan/dgit, so go's "git" invocations aren't reliable for me because what I'm trying to do is get them to be reliable..)

@bcmills sorry, I did a search but missed that one.

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