-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: only generate a go.mod file during 'go mod init'
In the general case, we do not know the correct module path for a new module unless we have checked its VCS tags for a major version. If we do not know the correct path, then we should not synthesize a go.mod file automatically from it. On the other hand, we don't want to run VCS commands in the working directory without an explicit request by the user to do so: 'go mod init' can reasonably invoke a VCS command, but 'go build' should not. Therefore, we should only create a go.mod file during 'go mod init'. This change removes the previous behavior of synthesizing a file automatically, and instead suggests a command that the user can opt to run explicitly. Updates golang#29433 Updates golang#27009 Updates golang#30228 Change-Id: I8c4554969db17156e97428df220b129a4d361040 Reviewed-on: https://go-review.googlesource.com/c/162699 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
- Loading branch information
Showing
14 changed files
with
162 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
env GO111MODULE=on | ||
|
||
# We should not create a go.mod file unless the user ran 'go mod init' explicitly. | ||
# However, we should suggest 'go mod init' if we can find an alternate config file. | ||
cd $WORK/test/x | ||
! go list . | ||
stderr 'found Gopkg.lock in .*[/\\]test' | ||
stderr '\s*cd \.\. && go mod init' | ||
|
||
# The command we suggested should succeed. | ||
cd .. | ||
go mod init | ||
go list -m all | ||
stdout '^m$' | ||
|
||
# In Plan 9, directories are automatically created in /n. | ||
# For example, /n/Gopkg.lock always exists, but it's a directory. | ||
# Test that we ignore directories when trying to find alternate config files. | ||
cd $WORK/gopkgdir/x | ||
! go list . | ||
stderr 'cannot find main module' | ||
! stderr 'Gopkg.lock' | ||
! stderr 'go mod init' | ||
|
||
-- $WORK/test/Gopkg.lock -- | ||
-- $WORK/test/x/x.go -- | ||
package x // import "m/x" | ||
-- $WORK/gopkgdir/Gopkg.lock/README.txt -- | ||
../Gopkg.lock is a directory, not a file. | ||
-- $WORK/gopkgdir/x/x.go -- | ||
package x // import "m/x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
env GO111MODULE=on | ||
|
||
# detect root of module tree as root of enclosing git repo | ||
# We should not create a go.mod file unless the user ran 'go mod init' explicitly. | ||
# However, we should suggest 'go mod init' if we can find an alternate config file. | ||
cd $WORK/test/x | ||
! go list . | ||
stderr 'found .git/config in .*[/\\]test' | ||
stderr '\s*cd \.\. && go mod init' | ||
|
||
# The command we suggested should succeed. | ||
cd .. | ||
go mod init | ||
go list -m all | ||
stdout '^m$' | ||
|
||
# We should not suggest creating a go.mod file in $GOROOT, even though there may be a .git/config there. | ||
cd $GOROOT | ||
! go list . | ||
! stderr 'go mod init' | ||
|
||
-- $WORK/test/.git/config -- | ||
-- $WORK/test/x/x.go -- | ||
package x // import "m/x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.