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 } */