mirror of
https://github.com/golang/go
synced 2024-11-23 18:10:04 -07:00
cmd/go: error out of 'go mod download' if the main module is passed as argument
Test added. Fixes #28338 Change-Id: Iab72ba5646360ae91671261161d8fda451f7a717 Reviewed-on: https://go-review.googlesource.com/c/go/+/189797 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
b3885dbc93
commit
696c41488a
@ -81,6 +81,17 @@ func runDownload(cmd *base.Command, args []string) {
|
|||||||
}
|
}
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
args = []string{"all"}
|
args = []string{"all"}
|
||||||
|
} else if modload.HasModRoot() {
|
||||||
|
modload.InitMod() // to fill Target
|
||||||
|
targetAtLatest := modload.Target.Path + "@latest"
|
||||||
|
targetAtUpgrade := modload.Target.Path + "@upgrade"
|
||||||
|
targetAtPatch := modload.Target.Path + "@patch"
|
||||||
|
for _, arg := range args {
|
||||||
|
switch arg {
|
||||||
|
case modload.Target.Path, targetAtLatest, targetAtUpgrade, targetAtPatch:
|
||||||
|
os.Stderr.WriteString("go mod download: skipping argument "+ arg + " that resolves to the main module\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var mods []*moduleJSON
|
var mods []*moduleJSON
|
||||||
@ -91,8 +102,9 @@ func runDownload(cmd *base.Command, args []string) {
|
|||||||
if info.Replace != nil {
|
if info.Replace != nil {
|
||||||
info = info.Replace
|
info = info.Replace
|
||||||
}
|
}
|
||||||
if info.Version == "" && info.Error == nil {
|
if (module.Version{Path: info.Path, Version: info.Version} == modload.Target) {
|
||||||
// main module
|
// skipping main module.
|
||||||
|
// go mod download without dependencies is silent.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
m := &moduleJSON{
|
m := &moduleJSON{
|
||||||
|
6
src/cmd/go/testdata/script/mod_download.txt
vendored
6
src/cmd/go/testdata/script/mod_download.txt
vendored
@ -93,6 +93,12 @@ stderr '^rsc.io/quote@v1.999.999: reading .*/v1.999.999.info: 404 Not Found$'
|
|||||||
! go mod download -json bad/path
|
! go mod download -json bad/path
|
||||||
stdout '^\t"Error": "module bad/path: not a known dependency"'
|
stdout '^\t"Error": "module bad/path: not a known dependency"'
|
||||||
|
|
||||||
|
# download main module returns an error
|
||||||
|
go mod download m
|
||||||
|
stderr '^go mod download: skipping argument m that resolves to the main module\n'
|
||||||
|
go mod download m@latest
|
||||||
|
stderr '^go mod download: skipping argument m@latest that resolves to the main module\n'
|
||||||
|
|
||||||
# allow go mod download without go.mod
|
# allow go mod download without go.mod
|
||||||
env GO111MODULE=auto
|
env GO111MODULE=auto
|
||||||
rm go.mod
|
rm go.mod
|
||||||
|
Loading…
Reference in New Issue
Block a user