diff --git a/go/cmd/dolt/commands/version.go b/go/cmd/dolt/commands/version.go index 9eaf4b7818..f4abff6d61 100644 --- a/go/cmd/dolt/commands/version.go +++ b/go/cmd/dolt/commands/version.go @@ -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 +} diff --git a/integration-tests/bats/no-repo.bats b/integration-tests/bats/no-repo.bats index ad3fdf0ee8..ed88cb5cc5 100755 --- a/integration-tests/bats/no-repo.bats +++ b/integration-tests/bats/no-repo.bats @@ -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" {