gitpb/rill.go

97 lines
2.2 KiB
Go

package gitpb
// runs git, parses output
// types faster than you can
import (
"errors"
"sort"
"strings"
"time"
"go.wit.com/log"
)
func (all *GitTags) SortByAge() *GitTagIterator {
packs := all.selectAllGitTag()
sort.Sort(GitTagAge(packs))
iterator := NewGitTagIterator(packs)
return iterator
}
type GitTagAge []*GitTag
func (a GitTagAge) Len() int { return len(a) }
// sorts in ? order
func (a GitTagAge) Less(i, j int) bool {
if time.Since(a[i].Authordate.AsTime()) < time.Since(a[j].Authordate.AsTime()) {
return true
}
return false
}
func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// rill is awesome. long live rill
// attempt scan with rill
func (all *Repos) rillGitPull() error {
loop := all.SortByGoPath()
for loop.Scan() {
t := loop.Next()
log.Info("repo", t.GoPath)
}
/*
packs := all.selectAllRepo()
// Convert a slice of user IDs into a channel
ids := rill.FromSlice(packs, nil)
// Read users from the API.
// Concurrency = 20
dirs := rill.Map(ids, 20, func(id string) (*Repo, error) {
return packs[id], nil
})
// Activate users.
// Concurrency = 10
err := rill.ForEach(dirs, 10, func(repo *Repo) error {
// could do something here
// fmt.Printf("Repo found : %s\n", repo.GoPath)
// repo.Run([]string{"git", "pull"})
return nil
})
*/
return nil
}
var ErrorMissingGitConfig error = errors.New("missing .git/config")
var ErrorGitPullOnLocal error = errors.New("git pull on local only branch")
// checks to see if you can do a 'git pull'
func (repo *Repo) IsOnlyLocalTag(currentName string) bool {
log.Warn("IsOnlyLocalTag(currentName string) not re-implemented yet")
return false
}
func (repo *Repo) GitPull() (string, error) {
currentName := repo.GetCurrentBranchName()
if repo.IsOnlyLocalTag(currentName) {
return "", ErrorGitPullOnLocal
}
var cmd []string
cmd = append(cmd, "git", "pull")
r := repo.Run(cmd)
output := strings.Join(r.Stdout, "\n")
if r.Error != nil {
output = "git error_,,,_a_,,,_b_,,,c"
}
if r.Error == nil {
log.Log(GITPBWARN, "git pull ran", repo.GetGoPath())
log.Log(GITPBWARN, "git pull output", output)
} else {
log.Log(GITPBWARN, "git pull error", repo.GetGoPath(), r.Error)
}
return output, r.Error
}