]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix get -tool when multiple packages are provided
authorwagner riffel <wgrriffel@gmail.com>
Sat, 7 Jun 2025 19:28:20 +0000 (16:28 -0300)
committerGopher Robot <gobot@golang.org>
Fri, 8 Aug 2025 17:48:08 +0000 (10:48 -0700)
Fixes #74035

Change-Id: I51865f4f753aade9a8be62ed6f9bc2d298742bf1
Reviewed-on: https://go-review.googlesource.com/c/go/+/679975
Reviewed-by: Ian Alexander <jitsu@google.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Sean Liao <sean@liao.dev>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
src/cmd/go/internal/modget/get.go
src/cmd/go/testdata/script/mod_get_tool_issue74035.txt [new file with mode: 0644]

index 31e9244e2dce54e045343af3ef89f0a4967e45c1..25dbf3972fd465368ed181210eba90257414af37 100644 (file)
@@ -453,7 +453,7 @@ func updateTools(ctx context.Context, queries []*query, opts *modload.WriteOpts)
                if queries[i].version == "none" {
                        opts.DropTools = append(opts.DropTools, m.Pkgs...)
                } else {
-                       opts.AddTools = append(opts.DropTools, m.Pkgs...)
+                       opts.AddTools = append(opts.AddTools, m.Pkgs...)
                }
        }
 }
diff --git a/src/cmd/go/testdata/script/mod_get_tool_issue74035.txt b/src/cmd/go/testdata/script/mod_get_tool_issue74035.txt
new file mode 100644 (file)
index 0000000..d6fa592
--- /dev/null
@@ -0,0 +1,25 @@
+# Regression test for https://go.dev/issue/74035.
+go get -tool example.com/foo/cmd/a example.com/foo/cmd/b
+cmp go.mod go.mod.want
+
+-- go.mod --
+module example.com/foo
+go 1.24
+-- go.mod.want --
+module example.com/foo
+
+go 1.24
+
+tool (
+       example.com/foo/cmd/a
+       example.com/foo/cmd/b
+)
+-- cmd/a/a.go --
+package a
+
+func main() {}
+
+-- cmd/b/b.go --
+package b
+
+func main() {}