-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It was panicking instead of printing a nice error. Fixes golang#61258. Fixes golang#61259. Change-Id: Ia30853db5bc7f1f2a4c7e91169c659ae2b79adcb Reviewed-on: https://go-review.googlesource.com/c/go/+/509097 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
- Loading branch information
Showing
4 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,15 @@ func (r *toolchainRepo) Versions(ctx context.Context, prefix string) (*Versions, | |
} | ||
} | ||
|
||
// Always include our own version. | ||
// This means that the development branch of Go 1.21 (say) will allow 'go get [email protected]' | ||
// even though there are no Go 1.21 releases yet. | ||
// Once there is a release, 1.21 will be treated as a query matching the latest available release. | ||
// Before then, 1.21 will be treated as a query that resolves to this entry we are adding (1.21). | ||
if v := gover.Local(); !have[v] { | ||
list = append(list, goPrefix+v) | ||
} | ||
|
||
if r.path == "go" { | ||
sort.Slice(list, func(i, j int) bool { | ||
return gover.Compare(list[i], list[j]) < 0 | ||
|
@@ -74,20 +83,27 @@ func (r *toolchainRepo) Versions(ctx context.Context, prefix string) (*Versions, | |
} | ||
|
||
func (r *toolchainRepo) Stat(ctx context.Context, rev string) (*RevInfo, error) { | ||
// If we're asking about "go" (not "toolchain"), pretend to have | ||
// all earlier Go versions available without network access: | ||
// we will provide those ourselves, at least in GOTOOLCHAIN=auto mode. | ||
if r.path == "go" && gover.Compare(rev, gover.Local()) <= 0 { | ||
return &RevInfo{Version: rev}, nil | ||
} | ||
|
||
// Convert rev to DL version and stat that to make sure it exists. | ||
// In theory the go@ versions should be like 1.21.0 | ||
// and the toolchain@ versions should be like go1.21.0 | ||
// but people will type the wrong one, and so we accept | ||
// both and silently correct it to the standard form. | ||
prefix := "" | ||
v := rev | ||
v = strings.TrimPrefix(v, "go") | ||
if r.path == "toolchain" { | ||
prefix = "go" | ||
} | ||
|
||
if !gover.IsValid(v) { | ||
return nil, fmt.Errorf("invalid %s version %s", r.path, rev) | ||
} | ||
// If we're asking about "go" (not "toolchain"), pretend to have | ||
// all earlier Go versions available without network access: | ||
// we will provide those ourselves, at least in GOTOOLCHAIN=auto mode. | ||
if r.path == "go" && gover.Compare(v, gover.Local()) <= 0 { | ||
return &RevInfo{Version: prefix + v}, nil | ||
} | ||
if gover.IsLang(v) { | ||
return nil, fmt.Errorf("go language version %s is not a toolchain version", rev) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
# setup | ||
env TESTGO_VERSION=go1.99.0 | ||
env TESTGO_VERSION=go1.99rc1 | ||
env TESTGO_VERSION_SWITCH=switch | ||
|
||
# go get go should use the latest Go 1.23 | ||
cp go.mod.orig go.mod | ||
go get go | ||
stderr '^go: upgraded go 1.21 => 1.23.9$' | ||
grep 'go 1.23.9' go.mod | ||
grep 'toolchain go1.99.0' go.mod | ||
grep 'toolchain go1.99rc1' go.mod | ||
|
||
# go get [email protected] should use the latest Go 1.23 | ||
cp go.mod.orig go.mod | ||
go get [email protected] | ||
stderr '^go: upgraded go 1.21 => 1.23.9$' | ||
grep 'go 1.23.9' go.mod | ||
grep 'toolchain go1.99.0' go.mod | ||
grep 'toolchain go1.99rc1' go.mod | ||
|
||
# go get [email protected] should use the latest Go 1.22 | ||
cp go.mod.orig go.mod | ||
go get [email protected] | ||
stderr '^go: upgraded go 1.21 => 1.22.9$' | ||
grep 'go 1.22.9' go.mod | ||
grep 'toolchain go1.99.0' go.mod | ||
grep 'toolchain go1.99rc1' go.mod | ||
|
||
# go get go@patch should use the latest patch release | ||
go get [email protected] | ||
go get go@patch | ||
stderr '^go: upgraded go 1.22.1 => 1.22.9$' | ||
grep 'go 1.22.9' go.mod | ||
grep 'toolchain go1.99.0' go.mod | ||
grep 'toolchain go1.99rc1' go.mod | ||
|
||
# go get [email protected] does NOT find the release candidate | ||
cp go.mod.orig go.mod | ||
|
@@ -40,20 +40,20 @@ cp go.mod.orig go.mod | |
go get [email protected] | ||
stderr '^go: upgraded go 1.21 => 1.24rc1$' | ||
grep 'go 1.24rc1' go.mod | ||
grep 'toolchain go1.99.0' go.mod | ||
grep 'toolchain go1.99rc1' go.mod | ||
|
||
# go get go@latest finds the latest Go 1.23 | ||
cp go.mod.orig go.mod | ||
go get go@latest | ||
stderr '^go: upgraded go 1.21 => 1.23.9$' | ||
grep 'go 1.23.9' go.mod | ||
grep 'toolchain go1.99.0' go.mod | ||
grep 'toolchain go1.99rc1' go.mod | ||
|
||
# Again, with toolchains. | ||
|
||
# go get toolchain should find go1.999testmod. | ||
go get toolchain | ||
stderr '^go: upgraded toolchain go1.99.0 => go1.999testmod$' | ||
stderr '^go: upgraded toolchain go1.99rc1 => go1.999testmod$' | ||
grep 'go 1.23.9' go.mod | ||
grep 'toolchain go1.999testmod' go.mod | ||
|
||
|
@@ -96,6 +96,33 @@ stderr '^go: added toolchain go1.999testmod$' | |
grep 'go 1.21' go.mod | ||
grep 'toolchain go1.999testmod' go.mod | ||
|
||
# Bug fixes. | ||
|
||
# go get go@garbage should fail but not crash | ||
! go get go@garbage | ||
! stderr panic | ||
stderr '^go: invalid go version garbage$' | ||
|
||
# go get [email protected] is OK - we silently correct to 1.21.0 | ||
go get [email protected] | ||
go get [email protected] | ||
stderr '^go: upgraded go 1.19 => 1.21.0' | ||
|
||
# go get [email protected] is OK too. | ||
go get [email protected] | ||
stderr '^go: downgraded toolchain go1.999testmod => go1.24rc1$' | ||
|
||
# go get [email protected] should work if we are the Go 1.21 language version, | ||
# even though there's no toolchain for it. | ||
# (Older versions resolve to the latest release in that version, so for example | ||
# go get [email protected] might resolve to 1.20.9, but if we're the devel copy of | ||
# Go 1.21, there's no release yet to resolve to, so we resolve to ourselves.) | ||
env TESTGO_VERSION=go1.21 | ||
go get [email protected] toolchain@none | ||
go get [email protected] | ||
grep 'go 1.21$' go.mod | ||
! grep toolchain go.mod | ||
|
||
-- go.mod.orig -- | ||
module m | ||
|
||
|