Skip to content

Commit a685a8d

Browse files
author
Bryan C. Mills
committed
cmd/go: make 'go get <module>@none' idempotent
Before this change, 'go get <module>@none' for a module not in the build list would add the module to go.mod (with the explicit version string "none"). Subsequent go commands would fail with 'invalid module version "none"'. Change-Id: Iebcaeab89eb19959f0a9aeda836f179962953313 Reviewed-on: https://go-review.googlesource.com/127215 Reviewed-by: Russ Cox <[email protected]>
1 parent 9ef5ee9 commit a685a8d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/cmd/go/internal/modget/get.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func runGet(cmd *base.Command, args []string) {
374374
// Now we know the specific version of each path@vers.
375375
// The final build list will be the union of three build lists:
376376
// 1. the original build list
377-
// 2. the modules named on the command line
377+
// 2. the modules named on the command line (other than @none)
378378
// 3. the upgraded requirements of those modules (if upgrading)
379379
// Start building those lists.
380380
// This loop collects (2).
@@ -395,7 +395,9 @@ func runGet(cmd *base.Command, args []string) {
395395
continue // already added
396396
}
397397
byPath[t.m.Path] = t
398-
named = append(named, t.m)
398+
if t.m.Version != "none" {
399+
named = append(named, t.m)
400+
}
399401
}
400402
base.ExitIfErrors()
401403

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
env GO111MODULE=on
2+
3+
go mod init example.com/foo
4+
5+
# 'go get bar@none' should be a no-op if module bar is not active.
6+
go get example.com/bar@none
7+
go list -m all
8+
! stdout example.com/bar
9+
10+
go get example.com/bar@none
11+
go list -m all
12+
! stdout example.com/bar

0 commit comments

Comments
 (0)