mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-08 08:49:52 -06:00
Merge pull request #7143 from dolthub/steph/version-fix
Poorly formatted version doesn't error
This commit is contained in:
@@ -148,13 +148,20 @@ func checkAndPrintVersionOutOfDateWarning(curVersion string, dEnv *env.DoltEnv)
|
||||
return errhand.BuildDError("error: failed to read version check file").AddCause(err).Build()
|
||||
}
|
||||
|
||||
latestRelease = string(vCheck)
|
||||
latestRelease = strings.ReplaceAll(string(vCheck), "\n", "")
|
||||
lastCheckDate, _ := dEnv.FS.LastModified(path)
|
||||
if lastCheckDate.Before(time.Now().AddDate(0, 0, -7)) {
|
||||
latestRelease, verr = getLatestDoltReleaseAndRecord(path, dEnv)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
} else {
|
||||
if !isVersionFormattedCorrectly(latestRelease) {
|
||||
latestRelease, verr = getLatestDoltReleaseAndRecord(path, dEnv)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
latestRelease, verr = getLatestDoltReleaseAndRecord(path, dEnv)
|
||||
@@ -217,3 +224,20 @@ func isOutOfDate(curVersion, latestRelease string) (bool, errhand.VerboseError)
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// isVersionFormattedCorrectly checks if the given version string is formatted correctly, i.e. is of the form
|
||||
// major.minor.patch where each part is an integer.
|
||||
func isVersionFormattedCorrectly(version string) bool {
|
||||
versionParts := strings.Split(version, ".")
|
||||
if len(versionParts) != 3 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, part := range versionParts {
|
||||
if _, err := strconv.Atoi(part); err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -156,6 +156,14 @@ teardown() {
|
||||
[[ ! "$output" =~ "Warning: you are on an old version of Dolt" ]] || false
|
||||
}
|
||||
|
||||
@test "no-repo: dolt version with bad version_check.txt does not print error" {
|
||||
echo "bad version" > $DOLT_ROOT_PATH/.dolt/version_check.txt
|
||||
|
||||
run dolt version
|
||||
[ "$status" -eq 0 ]
|
||||
[[ ! "$output" =~ "failed to parse version number" ]] || false
|
||||
}
|
||||
|
||||
# Tests for dolt commands outside of a dolt repository
|
||||
NOT_VALID_REPO_ERROR="The current directory is not a valid dolt repository."
|
||||
@test "no-repo: dolt status outside of a dolt repository" {
|
||||
|
||||
Reference in New Issue
Block a user