internal/stdlib: fix getGoRepo for requests to master

getGoRepo currently looks for a "master" tag when fetching the master
repo, instead of at the master branch. This is now fixed.

However, stdlib.semanticVersion still returns "master" when the
requestedVersion is "master", instead of returning a resolved semantic
version, so a fetch request for std@master will still result in a 500. A
comment is added to fix this in the future.

In a future CL, a fake pseudoversion will need to be constructed in
order to resolve std@master to a semantic version.

For golang/go#43890

Change-Id: I9e68b91d8c9e0bea6f6751d834853b852f0d532b
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/286153
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Trust: Julie Qiu <julie@golang.org>
This commit is contained in:
Julie Qiu 2021-01-24 22:31:47 -05:00
Родитель 8295319c9e
Коммит cd0dc1fcf8
1 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -180,13 +180,19 @@ var TestCommitTime = time.Date(2019, 9, 4, 1, 2, 3, 0, time.UTC)
func getGoRepo(version string) (_ *git.Repository, err error) {
defer derrors.Wrap(&err, "getGoRepo(%q)", version)
tag, err := TagForVersion(version)
if err != nil {
return nil, err
var ref plumbing.ReferenceName
if version == "master" {
ref = plumbing.HEAD
} else {
tag, err := TagForVersion(version)
if err != nil {
return nil, err
}
ref = plumbing.NewTagReferenceName(tag)
}
return git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: GoRepoURL,
ReferenceName: plumbing.NewTagReferenceName(tag),
ReferenceName: ref,
SingleBranch: true,
Depth: 1,
Tags: git.NoTags,
@ -375,6 +381,8 @@ func semanticVersion(requestedVersion string) (_ string, err error) {
}
return latestVersion, nil
case "master":
// TODO(https://github.com/golang/go/issues/43890): a semantic version
// needs to be returned here.
return requestedVersion, nil
default:
for _, v := range knownVersions {