summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-15 18:51:56 -0600
committerJeff Carr <[email protected]>2025-02-15 18:51:56 -0600
commit5d0f74360f7be1c5f7adced242e0a8e613fdcfd1 (patch)
tree5e0b00692d7d86e89f7f84378b25b767298a1883
parentc9149bbb13654d76518365d199dc0d51d6f5cfaf (diff)
finally use protobuf for thisv0.0.80
-rw-r--r--gitTag.common.go28
-rw-r--r--reload.go25
2 files changed, 30 insertions, 23 deletions
diff --git a/gitTag.common.go b/gitTag.common.go
index d349dea..43c0dbc 100644
--- a/gitTag.common.go
+++ b/gitTag.common.go
@@ -102,3 +102,31 @@ func (repo *Repo) IsLocalBranch(findname string) bool {
log.Log(INFO, "did not find tag:", findname, "in", repo.GetGoPath())
return false
}
+
+// finds the newest tag. used for deciding if master needs to be published
+func (repo *Repo) FindLastTag() string {
+ var newest *GitTag
+ all := repo.Tags.All()
+ for all.Scan() {
+ tag := all.Next()
+ if !strings.HasPrefix(tag.GetRefname(), "refs/tags/") {
+ continue
+ }
+ if newest == nil {
+ newest = tag
+ continue
+ }
+ cur := newest.Creatordate.AsTime()
+ if cur.Before(tag.Creatordate.AsTime()) {
+ newest = tag
+ }
+ // newtag := strings.TrimPrefix(tag.GetRefname(), "refs/tags/")
+ // log.Info("repo tag", tag.GetHash(), tag.Creatordate.AsTime(), tag.GetRefname(), newtag)
+ }
+ if newest == nil {
+ return ""
+ }
+ // log.Info("repo newest tag", newest.GetHash(), newest.Creatordate.AsTime(), newest.GetRefname())
+ newtag := strings.TrimPrefix(newest.GetRefname(), "refs/tags/")
+ return newtag
+}
diff --git a/reload.go b/reload.go
index 47d5aa4..60f3e7e 100644
--- a/reload.go
+++ b/reload.go
@@ -58,30 +58,9 @@ func (repo *Repo) SetUserBranchName(bname string) {
repo.UserBranchName = bname
}
-// updates LastTag // todo, get this from the protobuf
+// updates LastTag by age
func (repo *Repo) setLastTag() {
- cmd := []string{"git", "rev-list", "--tags", "--max-count=1"}
- result, _ := repo.RunQuiet(cmd)
- // log.Info("getLastTagVersion()", result.Stdout)
-
- if len(result.Stdout) != 1 {
- // log.Log(WARN, "no gitpb.LastTag() repo is broken. ignore this.", repo.GetGoPath())
- repo.LastTag = ""
- return
- }
-
- hash := result.Stdout[0]
-
- cmd = []string{"git", "describe", "--tags", "--always", hash}
- result, _ = repo.RunQuiet(cmd)
-
- if len(result.Stdout) != 1 {
- log.Log(WARN, "git LastTag() error:", result.Stdout, "hash =", hash)
- repo.LastTag = ""
- return
- }
-
- repo.LastTag = result.Stdout[0]
+ repo.LastTag = repo.FindLastTag()
}
func (repo *Repo) setCurrentBranchName() {