golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.89k stars 17.52k forks source link

cmd/go: 'go mod edit -replace' fails if the package's version in go.mod is not in semver format #34382

Open rafaelvanoni opened 5 years ago

rafaelvanoni commented 5 years ago

What version of Go are you using (go version)?

$ go version
go version go1.12 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rafael/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/rafael/Work/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go-1.12"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.12/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/rafael/Work/go/src/github.com/rafaelvanoni/kube-controllers-private/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build260011560=/tmp/go-build -gno-record-gcc-switches"

What did you do?

A simplified example suggested by @heschik is to run the following command twice:

go mod edit -replace golang.org/x/tools@latest=github.com/golang/tools@latest 

What did you expect to see?

What did you see instead?

A "version must be of the form v1.2.3" error.

rafaelvanoni commented 5 years ago

Workaround as suggested by @thepudds and @heschik is to run go list -m all or go mod tidy

rafaelvanoni commented 4 years ago

I'd be happy to contribute a patch if someone has a few minutes to point me in the right direction

hitzhangjie commented 4 years ago

go mod edit -replace old@${v}=new@{vv}, here, could we specify a branch for placeholder ${vv}.

Now it is not supported, a little inconvenient. But @commithash can workaround.