]> Cypherpunks repositories - gostls13.git/commit
cmd/go: fix get with the new 'work' pattern
authorMichael Matloob <matloob@golang.org>
Fri, 23 May 2025 17:19:44 +0000 (13:19 -0400)
committerMichael Matloob <matloob@google.com>
Tue, 27 May 2025 20:01:16 +0000 (13:01 -0700)
commit0e1b14bc2e13aed697854e3859f73ba4dba9fb22
tree0759fc15258c6e6a83cee0dbb839a64a5d9721d6
parent09f1546cba2998a8d89f4506c16ba3bff115071d
cmd/go: fix get with the new 'work' pattern

Before this change, go get didn't have support for the work pattern. The
work pattern is new in Go 1.25 and evaluates to the packages in the work
(also called main) modules. 'go get work' would cause a panic because
'work' would be incorrectly considered a path pattern and then queryPath
would would try to query a metapackage pattern (resulting in the
internal error panic). This change properly supports the work pattern in
go get.

It's pretty simple: First, we need to seprate the work pattern from the
other patterns. Then in performWorkQueries, which maps queries to the
modules that satisfy them, we return the single main module because by
definition the work pattern is the set of packages in the work modules,
and go get always runs in single module mode. (The exception is when the
work module contains no packages, in which case we report a warning, and
return no candidates because nothing is needed to resolve nothing).

The rest of the work is already done by loading the packages matching
the query and finding missing imports in the call to
findAndUpgradeImports in runGet.

Change-Id: I3c4610878b3d930a1d106cc59d9a0be194d966cd
Reviewed-on: https://go-review.googlesource.com/c/go/+/675895
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/cmd/go/internal/modget/get.go
src/cmd/go/testdata/script/mod_get_nopkgs.txt
src/cmd/go/testdata/script/mod_get_work.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_get_workspace_incomplete.txt [moved from src/cmd/go/testdata/script/mod_get_work_incomplete.txt with 98% similarity]