Go version

go1.23.10

Output of go env in your module/workspace:

GO111MODULE='ON'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/acedus/.cache/go-build'
GOENV='/home/acedus/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/acedus/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/acedus/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/usr/lib/golang'
GOSUMDB='off'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.10'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/acedus/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/acedus/dev/repos/kubevirt/go.mod'
GOWORK='/home/acedus/dev/repos/kubevirt/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3009368656=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Running go clean -mod=vendor in conjunction with go workspaces fails due to inconsistent vendoring despite having run go work vendor.

It appears that go clean doesn't call modload.InitWorkfile which in turn causes the command to be oblivious to workspaces. Adding modload.InitWorkfile to runClean fixes the issue.

What did you see happen?

go clean -mod=vendor
go: inconsistent vendoring in /home/acedus/dev/repos/kubevirt:
    kubevirt.io/api: is replaced in go.mod, but not marked as replaced in vendor/modules.txt
    kubevirt.io/client-go: is replaced in go.mod, but not marked as replaced in vendor/modules.txt

    To ignore the vendor directory, use -mod=readonly or -mod=mod.
    To sync the vendor directory, run:
        go mod vendor

What did you expect to see?

go clean -mod=vendor should succeed when used in conjunction with go workspaces.

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: gopherbot

Change https://go.dev/cl/682856 mentions this issue: cmd/go: clean should respect workspaces

Comment From: dmitshur

CC @golang/command-line.