summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-11-01 00:01:54 +0700
committerShulhan <ms@kilabit.info>2018-11-01 00:01:54 +0700
commite1993ddbadd8253f1fa65620b209b501ba70e44f (patch)
treebd2d761266bac3988b2824029caa8a378a196ded
parent20e98b127e16a40cf9f982cc44cc470ab73a8f9d (diff)
downloadbeku-e1993ddbadd8253f1fa65620b209b501ba70e44f.tar.xz
env: check if new package version is greater than current version
-rw-r--r--env.go5
-rw-r--r--package.go16
2 files changed, 17 insertions, 4 deletions
diff --git a/env.go b/env.go
index d7b35fa..81c13e5 100644
--- a/env.go
+++ b/env.go
@@ -1074,7 +1074,7 @@ func (env *Env) update(curPkg, newPkg *Package) (ok bool, err error) {
fmt.Println("[ENV] update >>>", newPkg)
}
- if curPkg.IsEqual(newPkg) {
+ if curPkg.IsEqual(newPkg) || !newPkg.IsNewer(curPkg) {
fmt.Println("[ENV] update >>> All package is up todate.")
ok = true
return
@@ -1275,9 +1275,10 @@ func (env *Env) SyncAll() (err error) {
return
}
- if pkg.Version == pkg.VersionNext {
+ if pkg.Version >= pkg.VersionNext {
fmt.Printf("[ENV] SyncAll %s >>> No update.\n\n",
pkg.ImportPath)
+ pkg.VersionNext = ""
continue
}
diff --git a/package.go b/package.go
index 56521cc..8b27e54 100644
--- a/package.go
+++ b/package.go
@@ -110,8 +110,8 @@ func (pkg *Package) CompareVersion(newPkg *Package) (err error) {
}
//
-// FetchLatestVersion will try to update the package and get the latest version (tag or
-// commit).
+// FetchLatestVersion will try to update the package and get the latest
+// version (tag or commit).
//
func (pkg *Package) FetchLatestVersion() (err error) {
switch pkg.vcsMode {
@@ -210,6 +210,18 @@ func (pkg *Package) IsEqual(other *Package) bool {
}
//
+// IsNewer will return true if current package is using tag and have newer
+// version that other package. If current package is not using tag, it's
+// always return true.
+//
+func (pkg *Package) IsNewer(older *Package) bool {
+ if !pkg.isTag {
+ return true
+ }
+ return pkg.Version >= older.Version
+}
+
+//
// Remove package installed binaries, archives, and source.
//
func (pkg *Package) Remove() (err error) {