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