86 lines
1.6 KiB
Go
86 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
git "go.wit.com/lib/libgit2"
|
|
"go.wit.com/log"
|
|
)
|
|
|
|
// are sent via -ldflags at buildtime
|
|
var VERSION string
|
|
var BUILDTIME string
|
|
|
|
func main() {
|
|
var repo *git.Repository
|
|
if argv.Refs {
|
|
repo, _ = showRefs()
|
|
} else {
|
|
testMessage()
|
|
}
|
|
if repo == nil {
|
|
os.Exit(-1)
|
|
}
|
|
b := walkBranches(repo)
|
|
|
|
// o, err := b.Reference.Peel(b.Reference.Type())
|
|
o, err := b.Reference.Peel(git.ObjectTree)
|
|
if err != nil {
|
|
log.Info("ref peel() failed", err)
|
|
return
|
|
}
|
|
t, errt := o.AsTree()
|
|
if errt != nil {
|
|
log.Info("object AsTree() failed", errt)
|
|
return
|
|
}
|
|
walkTree(t)
|
|
|
|
showtags(repo)
|
|
// v0.0.8
|
|
if argv.Tag != "" {
|
|
printCommitsForTag(repo, argv.Tag)
|
|
}
|
|
}
|
|
|
|
// lists the files in the git repo
|
|
// Makefile, .gitignore, README.md, etc
|
|
func walkTree(tree *git.Tree) {
|
|
var callCount int
|
|
err := tree.Walk(func(name string, entry *git.TreeEntry) error {
|
|
callCount++
|
|
log.Info("walkTree()", callCount, entry.Name, entry.Id, entry.Type)
|
|
|
|
return nil
|
|
})
|
|
log.Info("walkTree() count", callCount, err)
|
|
}
|
|
|
|
// lists the branches
|
|
// "master", "devel", "jcarr"
|
|
func walkBranches(repo *git.Repository) *git.Branch {
|
|
i, err := repo.NewBranchIterator(git.BranchLocal)
|
|
if err != nil {
|
|
log.Info("walkBranches() error", err)
|
|
return nil
|
|
}
|
|
|
|
for {
|
|
b, bt, err := i.Next()
|
|
if git.IsErrorCode(err, git.ErrorCodeIterOver) {
|
|
return nil
|
|
}
|
|
name, _ := b.Name()
|
|
if name == "jcarr" {
|
|
log.Info("found BranchLocal", name)
|
|
return b
|
|
}
|
|
if bt == git.BranchLocal {
|
|
log.Info("BranchLocal", name)
|
|
} else {
|
|
log.Info("Branch", name, bt)
|
|
}
|
|
}
|
|
return nil
|
|
}
|