Commit 5d750db0 authored by Russ Cox's avatar Russ Cox

cmd/go: fix go mod tidy crash on empty module

Fixes #27066.

Change-Id: Iede4385ad86b42d7d90814965b161a7e64d29833
Reviewed-on: https://go-review.googlesource.com/129799
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent cc880de4
......@@ -44,10 +44,11 @@ func runTidy(cmd *base.Command, args []string) {
// LoadALL adds missing modules.
// Remove unused modules.
used := map[module.Version]bool{modload.Target: true}
used := make(map[module.Version]bool)
for _, pkg := range modload.LoadALL() {
used[modload.PackageModule(pkg)] = true
}
used[modload.Target] = true // note: LoadALL initializes Target
inGoMod := make(map[string]bool)
for _, r := range modload.ModFile().Require {
......
......@@ -10,6 +10,10 @@ go list -m all
stdout '^w.1 v1.2.0'
stdout '^z.1 v1.2.0'
# empty tidy should not crash
cd triv
go mod tidy
-- go.mod --
module m
......@@ -55,3 +59,6 @@ module z
-- z/sub/sub.go --
package sub
-- triv/go.mod --
module triv
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment