mirror of
https://github.com/golang/go
synced 2024-11-07 23:56:16 -07:00
cmd/go: make 'go get <module>@none' idempotent
Before this change, 'go get <module>@none' for a module not in the build list would add the module to go.mod (with the explicit version string "none"). Subsequent go commands would fail with 'invalid module version "none"'. Change-Id: Iebcaeab89eb19959f0a9aeda836f179962953313 Reviewed-on: https://go-review.googlesource.com/127215 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
9ef5ee911c
commit
a685a8d114
@ -374,7 +374,7 @@ func runGet(cmd *base.Command, args []string) {
|
|||||||
// Now we know the specific version of each path@vers.
|
// Now we know the specific version of each path@vers.
|
||||||
// The final build list will be the union of three build lists:
|
// The final build list will be the union of three build lists:
|
||||||
// 1. the original build list
|
// 1. the original build list
|
||||||
// 2. the modules named on the command line
|
// 2. the modules named on the command line (other than @none)
|
||||||
// 3. the upgraded requirements of those modules (if upgrading)
|
// 3. the upgraded requirements of those modules (if upgrading)
|
||||||
// Start building those lists.
|
// Start building those lists.
|
||||||
// This loop collects (2).
|
// This loop collects (2).
|
||||||
@ -395,7 +395,9 @@ func runGet(cmd *base.Command, args []string) {
|
|||||||
continue // already added
|
continue // already added
|
||||||
}
|
}
|
||||||
byPath[t.m.Path] = t
|
byPath[t.m.Path] = t
|
||||||
named = append(named, t.m)
|
if t.m.Version != "none" {
|
||||||
|
named = append(named, t.m)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
base.ExitIfErrors()
|
base.ExitIfErrors()
|
||||||
|
|
||||||
|
12
src/cmd/go/testdata/script/mod_get_none.txt
vendored
Normal file
12
src/cmd/go/testdata/script/mod_get_none.txt
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
env GO111MODULE=on
|
||||||
|
|
||||||
|
go mod init example.com/foo
|
||||||
|
|
||||||
|
# 'go get bar@none' should be a no-op if module bar is not active.
|
||||||
|
go get example.com/bar@none
|
||||||
|
go list -m all
|
||||||
|
! stdout example.com/bar
|
||||||
|
|
||||||
|
go get example.com/bar@none
|
||||||
|
go list -m all
|
||||||
|
! stdout example.com/bar
|
Loading…
Reference in New Issue
Block a user