]> Cypherpunks repositories - gostls13.git/commit
cmd/go: fix go work sync when there are zero workspace modules
authorMichael Matloob <matloob@golang.org>
Thu, 18 Nov 2021 19:48:26 +0000 (14:48 -0500)
committerMichael Matloob <matloob@golang.org>
Mon, 22 Nov 2021 15:54:11 +0000 (15:54 +0000)
commite73c6c8808da281186a4d8f7107e34e9f7a4a9ee
tree3a344b163138e4b8b082858e852ed361ccad5b65
parentb2aa1380d9ad9a46eb98cd2e1ad71fcbccdc2bd1
cmd/go: fix go work sync when there are zero workspace modules

go work sync panics when there are no workspace modules. This is
because the code that set the pruning mode only did so with modules
present. This change changes pruningForGoVersion to properly return
workspace pruning in workspace mode to prevent that. Another weird
scenario can happen when there are no workspace modules, but the
command-line-arguments module is created by default. Check for that
when iterating over the workspace modules to avoid trying to find the
nonexistant go.mod file for that modules.

Fixes #49591

Change-Id: Iee8bc92a8aaf9c440f88fe4f9ca908a8d461cd36
Reviewed-on: https://go-review.googlesource.com/c/go/+/365234
Trust: Michael Matloob <matloob@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modload/modfile.go
src/cmd/go/internal/workcmd/sync.go
src/cmd/go/testdata/script/work_sync_missing_module.txt [new file with mode: 0644]