diff options
| author | Jeff Carr <[email protected]> | 2025-01-05 01:19:42 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-05 01:19:42 -0600 |
| commit | 2c3babe91788270e6c7746b0a87f4976f7945dc0 (patch) | |
| tree | c476cfd43b7f0683d6e302b89d5797456376af4b | |
| parent | 7f8cdac6fad06a548997f9bb1fbdc6507836efb0 (diff) | |
tries to dump some info about a repov0.0.3
| -rw-r--r-- | Makefile | 5 | ||||
| -rw-r--r-- | argv.go | 2 | ||||
| -rw-r--r-- | main.go | 13 | ||||
| -rw-r--r-- | message.go | 16 | ||||
| -rw-r--r-- | refs.go | 47 |
5 files changed, 64 insertions, 19 deletions
@@ -5,9 +5,10 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M) all: build build: goimports - GO111MODULE=off go build -v -x \ + PKG_CONFIG_PATH=/opt/libgit2/ GO111MODULE=off go build -v -x \ -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" - ./going2git -h + ldd going2git + ./going2git --refs --repo . vet: GO111MODULE=off go vet @@ -11,7 +11,7 @@ import ( var argv args type args struct { - Repo string `arg:"--repo" default:"./" help:"what .git repo to use?"` + RepoPath string `arg:"--repo" default:"./" help:"path to the .git repo"` Hostname string `arg:"--hostname" help:"hostname to use"` Refs bool `arg:"--refs" help:"list the git ref hashes"` } @@ -0,0 +1,13 @@ +package main + +// are sent via -ldflags at buildtime +var VERSION string +var BUILDTIME string + +func main() { + if argv.Refs { + showRefs() + } else { + testMessage() + } +} @@ -7,22 +7,6 @@ import ( "go.wit.com/log" ) -// are sent via -ldflags at buildtime -var VERSION string -var BUILDTIME string - -func main() { - if argv.Refs { - showRefs() - } else { - testMessage() - } -} - -func showRefs() { - log.Info("how do you do this with libgit2 and git2go? notsure.") -} - func testMessage() { var input git.Trailer @@ -0,0 +1,47 @@ +package main + +import ( + "fmt" + "os" + + git "go.wit.com/lib/libgit2" + "go.wit.com/log" +) + +func showRefs() 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 + } + ref, err := repo.Head() + log.Info("head", ref, err, ref.Name()) + fmt.Printf("%+v\n", ref) + walkRepo(repo) + return nil +} + +func walkRepo(repo *git.Repository) { + ri, err := repo.NewReferenceIterator() + exitIf(err) + + for { + ref, err := ri.Next() + if err != nil { + log.Info("done", err) + return + } + log.Info("head", ref, err, ref.Name(), ref.SymbolicTarget(), ref.Shorthand()) + // fmt.Printf("%+v\n", ref) + // SymbolicTarget() + } +} + +func exitIf(err error) { + if err == nil { + return + } + log.Info("exit due to error", err) + os.Exit(-1) +} |
