golang / go

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

cmd/go: 'go mod download' of a replaced module downloads the go.mod for its replacement #29181

Open bcmills opened 5 years ago

bcmills commented 5 years ago

go mod download of a specific version of a module should download only that module.

Today, if that version happens to have a replacement, go mod download also downloads the go.mod file (but not the .zip file) for its replacement.

``` $ go mod init golang.org/issue/scratch go: creating new go.mod: module golang.org/issue/scratch $ go mod edit -require golang.org/x/text@v0.2.0 $ go mod edit -replace golang.org/x/text@v0.2.0=golang.org/x/text@v0.3.0 $ go mod download -json golang.org/x/text@v0.2.0 go: finding golang.org/x/text v0.3.0 go: finding golang.org/x/text v0.2.0 { "Path": "golang.org/x/text", "Version": "v0.2.0", "Info": "/tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/cache/download/golang.org/x/text/@v/v0.2.0.info", "GoMod": "/tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/cache/download/golang.org/x/text/@v/v0.2.0.mod", "Zip": "/tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/cache/download/golang.org/x/text/@v/v0.2.0.zip", "Dir": "/tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/golang.org/x/text@v0.2.0", "Sum": "h1:WtDSLEtcB5GqbjSlyn8XcYtxjw+SgFMc2RILOvq7CuE=", "GoModSum": "h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=" } $ find $GOPATH -name '*.mod' /tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/cache/download/golang.org/x/text/@v/v0.2.0.mod /tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/cache/download/golang.org/x/text/@v/v0.3.0.mod $ find $GOPATH -name '*.zip' /tmp/tmp.3uwW75Tyk7/_gopath/pkg/mod/cache/download/golang.org/x/text/@v/v0.2.0.zip ```
bcmills commented 5 years ago

(Found while investigating #27868.)

oiooj commented 5 years ago

I fixed this problem in my local repo, but from the test script:

go mod download will not follow replacements for explicit module queries.

Maybe we need to think about it again.