more on branches
This commit is contained in:
parent
b5643f83be
commit
dbf1b08869
5
Makefile
5
Makefile
|
@ -25,3 +25,8 @@ goimports:
|
|||
install: goimports
|
||||
GO111MODULE=off go install \
|
||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||
|
||||
clean:
|
||||
rm -f go.*
|
||||
rm -f going2git
|
||||
-go-mod-clean --purge
|
||||
|
|
40
main.go
40
main.go
|
@ -1,13 +1,51 @@
|
|||
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 {
|
||||
showRefs()
|
||||
repo, _ = showRefs()
|
||||
} else {
|
||||
testMessage()
|
||||
}
|
||||
if repo == nil {
|
||||
os.Exit(-1)
|
||||
}
|
||||
walkBranches(repo)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
12
refs.go
12
refs.go
|
@ -8,18 +8,18 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
func showRefs() error {
|
||||
func showRefs() (*git.Repository, error) {
|
||||
log.Info("how do you do this with libgit2 and git2go? notsure.")
|
||||
repo, err := git.OpenRepository(argv.RepoPath)
|
||||
if err != nil {
|
||||
log.Info("open failed", argv.RepoPath, err)
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
ref, err := repo.Head()
|
||||
log.Info("head", ref, err, ref.Name())
|
||||
fmt.Printf("%+v\n", ref)
|
||||
walkRepo(repo)
|
||||
return nil
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
func walkRepo(repo *git.Repository) {
|
||||
|
@ -27,12 +27,14 @@ func walkRepo(repo *git.Repository) {
|
|||
exitIf(err)
|
||||
|
||||
for {
|
||||
ref, err := ri.Next()
|
||||
var ref *git.Reference
|
||||
var err error
|
||||
ref, err = ri.Next()
|
||||
if err != nil {
|
||||
log.Info("done", err)
|
||||
return
|
||||
}
|
||||
log.Info("head", ref, err, ref.Name(), ref.SymbolicTarget(), ref.Shorthand())
|
||||
log.Info("walkRepo() head", ref, err, "ref.Name =", ref.Name(), ref.SymbolicTarget(), ref.Shorthand())
|
||||
// fmt.Printf("%+v\n", ref)
|
||||
// SymbolicTarget()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue