get devel and user versions
This commit is contained in:
parent
96d37b5941
commit
d283d2d297
|
@ -4,6 +4,10 @@ package gitpb
|
||||||
// types faster than you can
|
// types faster than you can
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,8 +34,45 @@ func (repo *Repo) GetLastTag() string {
|
||||||
return result.Stdout[0]
|
return result.Stdout[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func (repo *Repo) GitMasterVersion() string {
|
||||||
func (repo *Repo) gitDescribeByName(name string) (string, error) {
|
v, err := repo.gitVersionByName("master")
|
||||||
|
/*
|
||||||
|
count := repo.LenGitTags()
|
||||||
|
log.Info(repo.GoPath, "tag count", count)
|
||||||
|
repo.UpdateGitTags()
|
||||||
|
count = repo.LenGitTags()
|
||||||
|
log.Info(repo.GoPath, "tag count", count)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return v
|
||||||
|
} else {
|
||||||
|
log.Info("GitMasterVersion() error", err)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repo) GitDevelVersion() string {
|
||||||
|
v, err := repo.gitVersionByName("devel")
|
||||||
|
if err == nil {
|
||||||
|
return v
|
||||||
|
} else {
|
||||||
|
log.Info("GitMasterVersion() error", err)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repo) GitUserVersion() string {
|
||||||
|
v, err := repo.gitVersionByName("jcarr")
|
||||||
|
if err == nil {
|
||||||
|
return v
|
||||||
|
} else {
|
||||||
|
log.Info("GitMasterVersion() error", err)
|
||||||
|
return "error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *Repo) gitVersionByName(name string) (string, error) {
|
||||||
name = strings.TrimSpace(name)
|
name = strings.TrimSpace(name)
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
|
@ -45,34 +86,37 @@ func (repo *Repo) gitDescribeByName(name string) (string, error) {
|
||||||
}
|
}
|
||||||
if !repo.LocalTagExists(name) {
|
if !repo.LocalTagExists(name) {
|
||||||
// tag does not exist
|
// tag does not exist
|
||||||
|
log.Warn("LocalTagExists()", name, "did not exist")
|
||||||
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
|
return "", errors.New("gitDescribeByName() git fatal: Not a valid object name")
|
||||||
}
|
}
|
||||||
cmd := []string{"git", "describe", "--tags", "--always", name}
|
cmd := []string{"git", "describe", "--tags", "--always", name}
|
||||||
r := repo.RunQuiet(cmd)
|
result := repo.RunQuiet(cmd)
|
||||||
output := strings.Join(r.Stdout, "\n")
|
output := strings.Join(result.Stdout, "\n")
|
||||||
if r.Error != nil {
|
if result.Error != nil {
|
||||||
log.Warn("cmd =", cmd)
|
log.Warn("cmd =", cmd)
|
||||||
log.Warn("err =", r.Error)
|
log.Warn("err =", result.Error)
|
||||||
log.Warn("not in a git repo or bad tag?", rs.Path())
|
log.Warn("not in a git repo or bad tag?", repo.GoPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimSpace(output), r.Error
|
return strings.TrimSpace(output), result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repo) LocalTagExists(findname string) bool {
|
func (repo *Repo) LocalTagExists(findname string) bool {
|
||||||
allTags := repo.Tags.ListAll()
|
loop := repo.AllTags()
|
||||||
for _, t := range allTags {
|
for loop.Scan() {
|
||||||
tagname := t.TagString()
|
t := loop.Next()
|
||||||
|
log.Info("tag:", t.Refname)
|
||||||
|
|
||||||
|
tagname := t.Refname
|
||||||
if strings.HasPrefix(tagname, "refs/remotes") {
|
if strings.HasPrefix(tagname, "refs/remotes") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
path, filename := filepath.Split(tagname)
|
path, filename := filepath.Split(tagname)
|
||||||
log.Log(INFO, "tag:", path, filename, "from", rs.Path())
|
log.Log(GITPB, "tag:", path, filename, "from", repo.GoPath)
|
||||||
if filename == findname {
|
if filename == findname {
|
||||||
log.Log(INFO, "found tag:", path, filename, "from", rs.Path())
|
log.Log(GITPBWARN, "found tag:", path, filename, "from", repo.GoPath)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ func (it *GitTagIterator) Scan() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GitTag returns the current repo.
|
// GitTag returns the current repo.
|
||||||
func (it *GitTagIterator) GitTag() *GitTag {
|
func (it *GitTagIterator) Next() *GitTag {
|
||||||
if it.packs[it.index-1] == nil {
|
if it.packs[it.index-1] == nil {
|
||||||
for i, d := range it.packs {
|
for i, d := range it.packs {
|
||||||
fmt.Println("i =", i, d)
|
fmt.Println("i =", i, d)
|
||||||
|
|
|
@ -55,17 +55,17 @@ func (repo *Repo) UpdateGitTags() error {
|
||||||
}
|
}
|
||||||
refname = parts[3]
|
refname = parts[3]
|
||||||
subject = parts[4]
|
subject = parts[4]
|
||||||
}
|
|
||||||
|
|
||||||
newr := GitTag{
|
newr := GitTag{
|
||||||
Refname: refname,
|
Refname: refname,
|
||||||
Objectname: hash,
|
Objectname: hash,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Creatordate: ctime,
|
Creatordate: ctime,
|
||||||
Authordate: atime,
|
Authordate: atime,
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.AppendGitTag(&newr)
|
repo.AppendGitTag(&newr)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue