tries to dump some info about a repo

This commit is contained in:
Jeff Carr 2025-01-05 01:19:42 -06:00
parent 7f8cdac6fa
commit 2c3babe917
5 changed files with 64 additions and 19 deletions

View File

@ -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

View File

@ -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"`
}

13
main.go Normal file
View File

@ -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()
}
}

View File

@ -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

47
refs.go Normal file
View File

@ -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)
}