mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/go: go clean should not accept flags like -modcache with packages
For #53725 Change-Id: I99a85b437d5f918dba74c4eccefcf8087193646a Reviewed-on: https://go-review.googlesource.com/c/go/+/425874 Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
67d85ad00f
commit
c22865fcfa
@ -118,6 +118,23 @@ func init() {
|
||||
}
|
||||
|
||||
func runClean(ctx context.Context, cmd *base.Command, args []string) {
|
||||
if len(args) > 0 {
|
||||
cacheFlag := ""
|
||||
switch {
|
||||
case cleanCache:
|
||||
cacheFlag = "-cache"
|
||||
case cleanTestcache:
|
||||
cacheFlag = "-testcache"
|
||||
case cleanFuzzcache:
|
||||
cacheFlag = "-fuzzcache"
|
||||
case cleanModcache:
|
||||
cacheFlag = "-modcache"
|
||||
}
|
||||
if cacheFlag != "" {
|
||||
base.Fatalf("go: clean %s cannot be used with package arguments", cacheFlag)
|
||||
}
|
||||
}
|
||||
|
||||
// golang.org/issue/29925: only load packages before cleaning if
|
||||
// either the flags and arguments explicitly imply a package,
|
||||
// or no other target (such as a cache) was requested to be cleaned.
|
||||
|
3
src/cmd/go/testdata/script/clean_cache_n.txt
vendored
3
src/cmd/go/testdata/script/clean_cache_n.txt
vendored
@ -15,6 +15,9 @@ exists $GOCACHE/00
|
||||
go clean -cache
|
||||
! exists $GOCACHE/00
|
||||
|
||||
! go clean -cache .
|
||||
stderr 'go: clean -cache cannot be used with package arguments'
|
||||
|
||||
-- main.go --
|
||||
package main
|
||||
|
||||
|
@ -8,6 +8,8 @@ go test x_test.go
|
||||
go clean -testcache
|
||||
go test x_test.go
|
||||
! stdout 'cached'
|
||||
! go clean -testcache ../x
|
||||
stderr 'go: clean -testcache cannot be used with package arguments'
|
||||
|
||||
# golang.org/issue/29100: 'go clean -testcache' should succeed
|
||||
# if the cache directory doesn't exist at all.
|
||||
|
@ -35,6 +35,9 @@ go clean -modcache
|
||||
! stderr 'finding rsc.io'
|
||||
go mod edit -droprequire rsc.io/quote
|
||||
|
||||
! go clean -modcache m
|
||||
stderr 'go: clean -modcache cannot be used with package arguments'
|
||||
|
||||
-- go.mod --
|
||||
module m
|
||||
-- m.go --
|
||||
|
@ -37,6 +37,9 @@ go test -fuzz=FuzzEmpty -fuzztime=2x .
|
||||
stdout 'new interesting: 0'
|
||||
stdout 'total: 1'
|
||||
|
||||
! go clean -fuzzcache example.com/y
|
||||
stderr 'go: clean -fuzzcache cannot be used with package arguments'
|
||||
|
||||
-- go.mod --
|
||||
module example.com/y
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user