summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-22 21:38:02 -0500
committerJeff Carr <[email protected]>2025-03-22 21:38:02 -0500
commitdbf1b088692b741d4f35e5f7d7ad99bbd327f70d (patch)
treee367d2b2b51d6f7db93fe37bfc4836483f24a9d6
parentb5643f83bef98d940f34a987a477436f91710e80 (diff)
more on branches
-rw-r--r--Makefile5
-rw-r--r--go.tools2
-rw-r--r--main.go40
-rw-r--r--refs.go12
4 files changed, 51 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 87e1555..c7ee16c 100644
--- a/Makefile
+++ b/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
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
diff --git a/main.go b/main.go
index 02da893..b2b0123 100644
--- a/main.go
+++ b/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
}
diff --git a/refs.go b/refs.go
index 8558029..debd187 100644
--- a/refs.go
+++ b/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()
}