Go1.12 fails in situation 1 and 2, and it succeeds in situation 3.
I think there are two things to be fixed.
go fmt doesn't need to find package github.com/a/b/c and it shouldn't run git. It can just reformat the file.
If the module github.com/a/b is in the directory ~/test and I am doing something with ~/test(such as cd ~/test; go build), go should look for github.com/a/b and github.com/a/b/c in ~/test. It shouldn't use git or request github.com to find the current module.
The text was updated successfully, but these errors were encountered:
Hmm, we could probably improve behavior here by ignoring imports when loading packages and rejecting package paths outside of the main module. We may be able to avoid loading the build list and going out to network that way.
#30577 is a dup that points to #27841: adding a -mod flag for go fmt. I don't think it makes sense to format sources in other modules though, so we don't need to load them.
I don't understand why go fmt needs to load packages.
If it just does the following things, what will be wrong?
go fmt path/to/file.go => gofmt -l -w path/to/file.go go fmt . => for f in ./*.go; do gofmt -l -w $f; done go fmt ./... => for f in **/*.go; do gofmt -l -w $f; done go fmt github.com/a/b => for f in $GOPATH/src/github.com/a/b/*.go; do gofmt -l -w $f; done