diff options
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | go.tools | 2 | ||||
| -rw-r--r-- | main.go | 40 | ||||
| -rw-r--r-- | refs.go | 12 |
4 files changed, 51 insertions, 8 deletions
@@ -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 diff --git a/go.tools b/go.tools deleted file mode 100644 index 157e620..0000000 --- a/go.tools +++ /dev/null @@ -1,2 +0,0 @@ -cmake -libssl-dev @@ -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 } @@ -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() } |
