Skip to content

Commit cc8ae42

Browse files
author
Bryan C. Mills
committed
cmd/go: retain sums for replacement modules in 'go mod tidy'
Fixes #27868 Change-Id: I6c2d221c4325a2f44625e797a82735d812ee0ec1 Reviewed-on: https://go-review.googlesource.com/c/153817 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 05bbec7 commit cc8ae42

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/cmd/go/internal/modcmd/tidy.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,17 @@ func modTidyGoSum() {
7777
keep := make(map[module.Version]bool)
7878
var walk func(module.Version)
7979
walk = func(m module.Version) {
80-
keep[m] = true
80+
// If we build using a replacement module, keep the sum for the replacement,
81+
// since that's the code we'll actually use during a build.
82+
//
83+
// TODO(golang.org/issue/29182): Perhaps we should keep both sums, and the
84+
// sums for both sets of transitive requirements.
85+
r := modload.Replacement(m)
86+
if r.Path == "" {
87+
keep[m] = true
88+
} else {
89+
keep[r] = true
90+
}
8191
list, _ := reqs.Required(m)
8292
for _, r := range list {
8393
if !keep[r] {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
env GO111MODULE=on
2+
3+
# After 'go get -d', the go.sum file should contain the sum for the module.
4+
go get -d rsc.io/[email protected]
5+
grep 'rsc.io/quote v1.5.0' go.sum
6+
7+
# If we replace the module and run 'go mod tidy', we should get a sum for the replacement.
8+
go mod edit -replace rsc.io/[email protected]=rsc.io/[email protected]
9+
go mod tidy
10+
grep 'rsc.io/quote v1.5.1' go.sum
11+
cp go.sum go.sum.tidy
12+
13+
# 'go mod vendor' should preserve that sum, and should not need to add any new entries.
14+
go mod vendor
15+
grep 'rsc.io/quote v1.5.1' go.sum
16+
cmp go.sum go.sum.tidy
17+
18+
-- go.mod --
19+
module golang.org/issue/27868
20+
21+
require rsc.io/quote v1.5.0
22+
23+
-- main.go --
24+
package main
25+
26+
import _ "rsc.io/quote"
27+
28+
func main() {}

0 commit comments

Comments
 (0)