From 96d37b5941717f9c3852429ba25420c6ccb3f997 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Nov 2024 01:23:51 -0600 Subject: rename this protobuf to something more specific --- gitTags.query.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 gitTags.query.go (limited to 'gitTags.query.go') 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 +} +*/ -- cgit v1.2.3