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: go mod edit --replace doesn't work with newly added go.mod in subdirectory #43781

Closed
fishy opened this issue Jan 19, 2021 · 1 comment

Comments

@fishy
Copy link

fishy commented Jan 19, 2021

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

$ go version
go version go1.15.6 linux/amd64

Does this issue reproduce with the latest release?

This is the latest release

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

go env Output
$ go env

What did you do?

The current master branch of github.com/apache/thrift doesn't have go.mod files (as of 0e68e8c51b2924d211a47978c80c6753f45e8af3)

I'm trying to add go.mod file in a new Pull Request, into a subdirectory (lib/go/thrift/go.mod), as in https://github.com/apache/thrift/pull/2309/files#diff-56d7575d9a6d7b2ca71217a3d9f49f9ba4354af736d0b96df07401c2782c1ed6:

module github.com/apache/thrift/lib/go/thrift

go 1.14

Then I tried to test this upgrade in another repo importing thrift, by:

go mod edit --replace=github.com/apache/thrift=github.com/fishy/thrift@a25cee372

But then go mod tidy fails with:

github.com/apache/thrift/lib/go/thrift: module github.com/apache/thrift@latest found (v0.13.0, replaced by github.com/fishy/thrift@v0.13.1-0.20210119191924-a25cee37208b), but does not contain package github.com/apache/thrift/lib/go/thrift

What did you expect to see?

This go mod edit --replace should work and not causing any errors.

What did you see instead?

See the error above.

I tried to create a completely new repo with go.mod file in a subdir, and importing that repo from another repo seem to work. I also tried to:

  1. Create a repo (A), with no go.mod file, and go library code in a subdir
  2. Import repo A from a different repo (B)
  3. Add go.mod to repo A's subdir
  4. upgrade repo B's A dependency to the new one with go.mod under subdir

And that seems to work as well, so the problem seems to only exist when go mod edit --replace is involved.

I mainly want to test that this thrift PR works before merging it, but since go mod edit --replace causes problems I cannot actually test it without merging it.

@seankhliao seankhliao added GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 19, 2021
@seankhliao
Copy link
Member

Require and replace operate on modules, not repositories.
Your existing require is for a (synthesized) module named github.com/apache/thrift, your replace targets the (synthesized) module at github.com/fishy/thrift which is separate from the module you created at github.com/fishy/thrift/lib/go/thrift.

If you want to test this, remove the existing require for github.com/apache/thrift (it will conflict), add a require for the new module github.com/apache/thrift/lib/go/thrift (can be any version, eg v0.0.0) and add a replace matching the new module go mod edit -replace=github.com/apache/thrift/lib/go/thrift=github.com/fishy/thrift/lib/go/thrift@a25cee372

For a seamless upgrade experience for downstream users, you should really consider placing the module at the repo root, it'll also make the tagging less complex.

I'm going to close this as working as intended, please comment if you disagree and refer to https://github.com/golang/go/wiki/Questions for questions

@seankhliao seankhliao removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 19, 2021
@golang golang locked and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants