summaryrefslogtreecommitdiffstats
path: root/internal/utils/version.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/utils/version.go')
-rw-r--r--internal/utils/version.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/internal/utils/version.go b/internal/utils/version.go
index 42a6d40..2b52a8b 100644
--- a/internal/utils/version.go
+++ b/internal/utils/version.go
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
+ "runtime/debug"
"strings"
"syscall"
@@ -15,6 +16,16 @@ var (
RepositoryURL = "[email protected]:repos/dborg.git"
)
+func init() {
+ if Version == "dev" {
+ if info, ok := debug.ReadBuildInfo(); ok {
+ if info.Main.Version != "" && info.Main.Version != "(devel)" {
+ Version = info.Main.Version
+ }
+ }
+ }
+}
+
func CheckForUpdates(cmd *cobra.Command) error {
if !isTerminal() {
return nil
@@ -57,10 +68,30 @@ func getLatestRemoteTag() (string, error) {
}
func isNewerVersion(remote, local string) bool {
+ if local == "dev" || local == "(devel)" {
+ return false
+ }
+
remote = strings.TrimPrefix(remote, "v")
local = strings.TrimPrefix(local, "v")
- return remote != local && remote > local
+ if remote == local {
+ return false
+ }
+
+ remoteParts := strings.Split(remote, ".")
+ localParts := strings.Split(local, ".")
+
+ for i := 0; i < len(remoteParts) && i < len(localParts); i++ {
+ if remoteParts[i] > localParts[i] {
+ return true
+ }
+ if remoteParts[i] < localParts[i] {
+ return false
+ }
+ }
+
+ return len(remoteParts) > len(localParts)
}
func promptAndUpdate(newVersion string) {