summaryrefslogtreecommitdiff
path: root/gitTags.query.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-29 01:23:51 -0600
committerJeff Carr <[email protected]>2024-11-29 01:23:51 -0600
commit96d37b5941717f9c3852429ba25420c6ccb3f997 (patch)
tree96ce9881925f71ea41effd3660ef24c318ddad61 /gitTags.query.go
parent3b90d979d73da9896570d2dc927e05e769b9670b (diff)
rename this protobuf to something more specific
Diffstat (limited to 'gitTags.query.go')
-rw-r--r--gitTags.query.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/gitTags.query.go b/gitTags.query.go
new file mode 100644
index 0000000..faea8e2
--- /dev/null
+++ b/gitTags.query.go
@@ -0,0 +1,78 @@
+package gitpb
+
+// runs git, parses output
+// types faster than you can
+
+import (
+ "go.wit.com/log"
+)
+
+func (repo *Repo) GetLastTag() string {
+ cmd := []string{"git", "rev-list", "--tags", "--max-count=1"}
+ result := repo.RunQuiet(cmd)
+ log.Info("getLastTagVersion()", result.Stdout)
+
+ if len(result.Stdout) != 1 {
+ log.Info("git LastTag() error:", result.Stdout)
+ return "error"
+ }
+
+ hash := result.Stdout[0]
+
+ cmd = []string{"git", "describe", "--tags", "--always", hash}
+ result = repo.RunQuiet(cmd)
+
+ if len(result.Stdout) != 1 {
+ log.Info("git LastTag() error:", result.Stdout)
+ return "error"
+ }
+
+ return result.Stdout[0]
+}
+
+/*
+func (repo *Repo) gitDescribeByName(name string) (string, error) {
+ name = strings.TrimSpace(name)
+
+ if name == "" {
+ // git will return the current tag
+ r := repo.RunQuiet([]string{"git", "describe", "--tags", "--always"})
+ output := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ log.Warn("gitDescribeByName() not in a git repo?", r.Error, repo.GoPath)
+ }
+ return strings.TrimSpace(output), r.Error
+ }
+ if !repo.LocalTagExists(name) {
+ // tag does not exist
+ return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
+ }
+ cmd := []string{"git", "describe", "--tags", "--always", name}
+ r := repo.RunQuiet(cmd)
+ output := strings.Join(r.Stdout, "\n")
+ if r.Error != nil {
+ log.Warn("cmd =", cmd)
+ log.Warn("err =", r.Error)
+ log.Warn("not in a git repo or bad tag?", rs.Path())
+ }
+
+ return strings.TrimSpace(output), r.Error
+}
+
+func (repo *Repo) LocalTagExists(findname string) bool {
+ allTags := repo.Tags.ListAll()
+ for _, t := range allTags {
+ tagname := t.TagString()
+ if strings.HasPrefix(tagname, "refs/remotes") {
+ continue
+ }
+ path, filename := filepath.Split(tagname)
+ log.Log(INFO, "tag:", path, filename, "from", rs.Path())
+ if filename == findname {
+ log.Log(INFO, "found tag:", path, filename, "from", rs.Path())
+ return true
+ }
+ }
+ return false
+}
+*/