golang / go

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

cmd/go: go get removes direct dependency #57683

Closed andig closed 1 year ago

andig commented 1 year ago

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

$ go version
go version go1.19.4 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/andig/Library/Caches/go-build"
GOENV="/Users/andig/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/andig/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/andig/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.19.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/andig/htdocs/evcc/go.mod"
GOWORK=""
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/sv/rs_453y57xj86xsbz3kw1mbc0000gn/T/go-build4107096655=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.19.4 darwin/arm64
GOROOT/bin/go tool compile -V: compile version go1.19.4
uname -v: Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103
ProductName:        macOS
ProductVersion:     13.1
BuildVersion:       22C65
lldb --version: lldb-1400.0.38.17
Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)

What did you do?

Run go get on clean go.mod:

 evcc master ≡  ❯
go mod tidy

 evcc master ≡  ❯
go get github.com/traefik/yaegi
go: added github.com/traefik/yaegi v0.14.3
go: removed github.com/volkszaehler/mbmd v0.0.0-20221223133217-870b3b92b81e

What did you expect to see?

No removal of unrelated modules

What did you see instead?

mbmd module removed for unknown reason:

diff --git a/go.mod b/go.mod
index b40aa02b1..c377e97fc 100644
--- a/go.mod
+++ b/go.mod
@@ -86,7 +86,6 @@ require (
        github.com/spf13/viper v1.14.0
        github.com/stretchr/testify v1.8.1
        github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c
-       github.com/volkszaehler/mbmd v0.0.0-20221223133217-870b3b92b81e
        github.com/writeas/go-strip-markdown v2.0.1+incompatible
        gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
        golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15
@@ -176,6 +175,7 @@ require (
        github.com/spf13/cast v1.5.0 // indirect
        github.com/subosito/gotenv v1.4.1 // indirect
        github.com/teivah/onecontext v1.3.0 // indirect
+       github.com/traefik/yaegi v0.14.3 // indirect
        github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
        github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
        gitlab.com/c0b/go-ordered-json v0.0.0-20201030195603-febf46534d5a // indirect

This happens on https://github.com/evcc-io/evcc/commit/c18475b050e4b770c1fc0a26e2799109e7454309

Running tidy once more re-adds the removed module:

go mod tidy
go: finding module for package github.com/volkszaehler/mbmd/meters/rs485
go: finding module for package github.com/volkszaehler/mbmd/meters
go: finding module for package github.com/volkszaehler/mbmd/encoding
go: finding module for package github.com/volkszaehler/mbmd/meters/sunspec
go: found github.com/volkszaehler/mbmd/encoding in github.com/volkszaehler/mbmd v0.0.0-20221223133217-870b3b92b81e
go: found github.com/volkszaehler/mbmd/meters/rs485 in github.com/volkszaehler/mbmd v0.0.0-20221223133217-870b3b92b81e
go: found github.com/volkszaehler/mbmd/meters in github.com/volkszaehler/mbmd v0.0.0-20221223133217-870b3b92b81e
go: found github.com/volkszaehler/mbmd/meters/sunspec in github.com/volkszaehler/mbmd v0.0.0-20221223133217-870b3b92b81e
bcmills commented 1 year ago

Thanks for the report. I suspect that this is related to #55955.

zakcutner commented 1 year ago

Hello! Is there any known workaround to this? I'm seeing it too: the effect is that this forces me to update the removed modules, since when they are re-added with go mod tidy the latest version is fetched

Edit: in case it helps anyone else, I've found that I can get around this by manually editing the go.mod file with the new dependency/version and then running go mod tidy 🙂

bcmills commented 1 year ago

Confirmed, this will be fixed by https://go.dev/cl/471595.

bcmills commented 1 year ago

Duplicate of #55955.