mirror of
https://github.com/golang/go
synced 2024-11-27 04:31:21 -07:00
cmd/go: improve pseudo-version timestamp error
The previous "invalid pseudo-version: does not match version-control timestamp" error message used a different timestamp format than the format used in go.mod and go.sum. For cut-and-paste-ability this patch makes the two consistent. Fixes #36974 Change-Id: I21f344ab9898cc584c0bcf4a75d74275a703c650 Reviewed-on: https://go-review.googlesource.com/c/go/+/217437 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
c4113b64c2
commit
e221a75dea
@ -563,7 +563,7 @@ func (r *codeRepo) validatePseudoVersion(info *codehost.RevInfo, version string)
|
||||
return err
|
||||
}
|
||||
if !t.Equal(info.Time.Truncate(time.Second)) {
|
||||
return fmt.Errorf("does not match version-control timestamp (%s)", info.Time.UTC().Format(time.RFC3339))
|
||||
return fmt.Errorf("does not match version-control timestamp (expected %s)", info.Time.UTC().Format(pseudoVersionTimestampFormat))
|
||||
}
|
||||
|
||||
tagPrefix := ""
|
||||
|
@ -48,6 +48,8 @@ import (
|
||||
|
||||
var pseudoVersionRE = lazyregexp.New(`^v[0-9]+\.(0\.0-|\d+\.\d+-([^+]*\.)?0\.)\d{14}-[A-Za-z0-9]+(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$`)
|
||||
|
||||
const pseudoVersionTimestampFormat = "20060102150405"
|
||||
|
||||
// PseudoVersion returns a pseudo-version for the given major version ("v1")
|
||||
// preexisting older tagged version ("" or "v1.2.3" or "v1.2.3-pre"), revision time,
|
||||
// and revision identifier (usually a 12-byte commit hash prefix).
|
||||
@ -55,7 +57,7 @@ func PseudoVersion(major, older string, t time.Time, rev string) string {
|
||||
if major == "" {
|
||||
major = "v0"
|
||||
}
|
||||
segment := fmt.Sprintf("%s-%s", t.UTC().Format("20060102150405"), rev)
|
||||
segment := fmt.Sprintf("%s-%s", t.UTC().Format(pseudoVersionTimestampFormat), rev)
|
||||
build := semver.Build(older)
|
||||
older = semver.Canonical(older)
|
||||
if older == "" {
|
||||
|
@ -76,17 +76,17 @@ cp go.mod.orig go.mod
|
||||
go mod edit -require golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c
|
||||
cd outside
|
||||
! go list -m golang.org/x/text
|
||||
stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(2017-09-15T03:28:32Z\)'
|
||||
stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)'
|
||||
cd ..
|
||||
! go list -m golang.org/x/text
|
||||
stderr 'golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(2017-09-15T03:28:32Z\)'
|
||||
stderr 'golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)'
|
||||
|
||||
# A 'replace' directive in the main module can replace an invalid timestamp
|
||||
# with a valid one.
|
||||
go mod edit -replace golang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c=golang.org/x/text@14c0d48ead0c
|
||||
cd outside
|
||||
! go list -m golang.org/x/text
|
||||
stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(2017-09-15T03:28:32Z\)'
|
||||
stderr 'go: example.com@v0.0.0 requires\n\tgolang.org/x/text@v0.1.1-0.20190915032832-14c0d48ead0c: invalid pseudo-version: does not match version-control timestamp \(expected 20170915032832\)'
|
||||
cd ..
|
||||
go list -m golang.org/x/text
|
||||
stdout 'golang.org/x/text v0.1.1-0.20190915032832-14c0d48ead0c => golang.org/x/text v0.1.1-0.20170915032832-14c0d48ead0c'
|
||||
|
Loading…
Reference in New Issue
Block a user