Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: Replace a v2 mod where there isn't a v2 directory #49444

Closed
shou1dwe opened this issue Nov 8, 2021 · 2 comments
Closed

cmd/go: Replace a v2 mod where there isn't a v2 directory #49444

shou1dwe opened this issue Nov 8, 2021 · 2 comments
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@shou1dwe
Copy link

shou1dwe commented Nov 8, 2021

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

$ go version
go version go1.17.2 darwin/arm64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/myusername/Library/Caches/go-build"
GOENV="/Users/myusername/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/myusername/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/myusername/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/myusername/Documents/gitroot/modimport/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2_/wb7qpk5n21l9yw2f1kj1_jj00000gn/T/go-build556537930=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have two repositories, one library: https://github.com/shou1dwe/modoriginal with a go.mod like:

module my.com/modoriginal

go 1.17

Its go.mod contains a name different from its VCS location: my.com/modoriginal

When using this library from another repository https://github.com/shou1dwe/modimport
A replace is required in go.mod like below:

module github.com/shou1dwe/modimport

go 1.17

require my.com/modoriginal v1.0.0

replace my.com/modoriginal => github.com/shou1dwe/modoriginal v1.0.0

With this setup, go run main.go in modimport repository works fine, everything works.

Then my.com/modoriginal author decided to introduce a breaking change and follow this guide: https://go.dev/blog/v2-go-modules, but decided to go with "major versions on separate branches" approach. So now there is https://github.com/shou1dwe/modoriginal/tree/v2 and also tag v2.0.0 created from the latest commit on v2 branch.

And modimport tries to use the same approach to retrieve new v2 version of modoriginal

module github.com/shou1dwe/modimport

go 1.17

require my.com/modoriginal/v2 v2.0.0

replace my.com/modoriginal/v2 => github.com/shou1dwe/modoriginal v2.0.0

What did you expect to see?

go mod tidy in modimport should exit 0 and return
go run main.go in modimport should print prefix test

What did you see instead?

$ go mod tidy                                 
go: errors parsing go.mod:
/Users/myuser/Documents/gitroot/modimport/go.mod:7: replace github.com/shou1dwe/modoriginal: version "v3.0.0" invalid: should be v0 or v1, not v3

$ go run main.go 
go: errors parsing go.mod:
/Users/myuser/Documents/gitroot/modimport/go.mod:7: replace github.com/shou1dwe/modoriginal: version "v2.0.0" invalid: should be v0 or v1, not v2
@bcmills
Copy link
Contributor

bcmills commented Nov 8, 2021

The error message here is correct, if somewhat unclear (that's #41512). The v2.0.0 version implies that the module path has a /v2 suffix, and the replacement needs to use that suffix too:

diff --git c/go.mod w/go.mod
index ec2f66b..9fe80b6 100644
--- c/go.mod
+++ w/go.mod
@@ -4,4 +4,4 @@ go 1.17

 require my.com/modoriginal/v2 v2.0.0

-replace my.com/modoriginal/v2 => github.com/shou1dwe/modoriginal v2.0.0
+replace my.com/modoriginal/v2 => github.com/shou1dwe/modoriginal/v2 v2.0.0
diff --git c/go.sum w/go.sum
index 366b3b7..0dbb54a 100644
--- c/go.sum
+++ w/go.sum
@@ -1,2 +1,4 @@
 github.com/shou1dwe/modoriginal v1.0.0 h1:FMM6zxAjkflLwFL1gbHxRTNTBeL0Ud4mUNWIszwg/Og=
 github.com/shou1dwe/modoriginal v1.0.0/go.mod h1:wToed6ZhC0LGFCfmM/5OuDEnsLfHfytDHy0XVW2BXWA=
+github.com/shou1dwe/modoriginal/v2 v2.0.0 h1:5C/g7vxq84qXhHS6YSsubf1yA69MLoWtb/2gssf1p0o=
+github.com/shou1dwe/modoriginal/v2 v2.0.0/go.mod h1:ClKiTOWxsK9gcPPdBI7f0sHmj8aw8+AFOm3/JIeivXg=
/tmp/modimport$ go list -m all
github.com/shou1dwe/modimport
my.com/modoriginal/v2 v2.0.0 => github.com/shou1dwe/modoriginal/v2 v2.0.0

@bcmills bcmills added modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Nov 8, 2021
@bcmills bcmills changed the title Replace a v2 mod where there isn't a v2 directory cmd/go: Replace a v2 mod where there isn't a v2 directory Nov 8, 2021
@shou1dwe
Copy link
Author

shou1dwe commented Nov 9, 2021

thanks, I can confirm that appending /v2 to right-hand side of the replace directive fixed the problem.
For me the confusing part is that I have been treating github.com/shou1dwe/modoriginal in the above context a VCS location rather than a "module name" or "module path"; and modoriginl's go.mod says the module name is my.com/modoriginal/v2.
Apparently the major version suffix rule applies to both places.

@golang golang locked and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants