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: mod tidy removes replaced go.sum entries #31190

Closed
eliasnaur opened this issue Apr 1, 2019 · 2 comments
Closed

cmd/go: mod tidy removes replaced go.sum entries #31190

eliasnaur opened this issue Apr 1, 2019 · 2 comments

Comments

@eliasnaur
Copy link
Contributor

eliasnaur commented Apr 1, 2019

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

$ go version
go version devel +b9b01ed56f Fri Mar 29 12:18:07 2019 +0100 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

I have a repository with two submodules, a library module and a main module depending on the library module. For convenience when working on both modules at the same time, I want to use a replace directive to point to the local path of the library. It's described in https://github.com/golang/go/wiki/Modules:

replace also can be used to inform the go tooling of the relative or absolute on-disk location of
modules in a multi-module project, such as:

replace example.com/project/foo => ../foo

I plan to check in the replace directive to the project repository, because it will be ignored by external modules importing main.

However, running go mod tidy when the main module contains a replace directive, the go.sum entries disappear:

$ git clone https://github.com/eliasnaur/gomodtidy.git
Cloning into 'gomodtidy'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 2), reused 17 (delta 2), pack-reused 0
Unpacking objects: 100% (17/17), done.
$ cd gomodtidy/main/
$ cat go.sum 
github.com/eliasnaur/gomodtidy/lib v0.0.0-20190401155538-6de8c4f5b51e h1:CgKA/cdZwECjX9i6bSRVHgjDA1Ik1xAKy86Fdm7lxU8=
github.com/eliasnaur/gomodtidy/lib v0.0.0-20190401155538-6de8c4f5b51e/go.mod h1:1/0i90HQ12RlIgzNk8GUdrWv8IQQA5d5dmJpmNqvLJo=
$ go mod edit -replace github.com/eliasnaur/gomodtidy/lib=../lib
$ go mod tidy
$ git diff
diff --git a/main/go.mod b/main/go.mod
index 2f5d4cb..bd0502c 100644
--- a/main/go.mod
+++ b/main/go.mod
@@ -3,3 +3,5 @@ module github.com/eliasnaur/gomodtidy/main
 go 1.13
 
 require github.com/eliasnaur/gomodtidy/lib v0.0.0-20190401155538-6de8c4f5b51e
+
+replace github.com/eliasnaur/gomodtidy/lib => ../lib
diff --git a/main/go.sum b/main/go.sum
index c537139..e69de29 100644
--- a/main/go.sum
+++ b/main/go.sum
@@ -1,2 +0,0 @@
-github.com/eliasnaur/gomodtidy/lib v0.0.0-20190401155538-6de8c4f5b51e h1:CgKA/cdZwECjX9i6bSRVHgjDA1Ik1xAKy86Fdm7lxU8=
-github.com/eliasnaur/gomodtidy/lib v0.0.0-20190401155538-6de8c4f5b51e/go.mod h1:1/0i90HQ12RlIgzNk8GUdrWv8IQQA5d5dmJpmNqvLJo=

What did you expect to see?

The go.sum lines were kept for the lib module.

What did you see instead?

go mod tidy removes the replaced module's go.sum lines. The lines are technically not used, but will be when the main is not the main module, e.g. someone imports github.com/eliasnaur/gomodtidy/main.

@bcmills
Copy link
Contributor

bcmills commented Apr 1, 2019

Dup of #29182.

@bcmills bcmills closed this as completed Apr 1, 2019
@bcmills
Copy link
Contributor

bcmills commented Apr 1, 2019

(Also note that go.sum entries outside of the main module are currently ignored; see #28802.)

@golang golang locked and limited conversation to collaborators Mar 31, 2020
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