From f1643ffcbd543cacfe9ab5e46eafdd0c39cd47fd Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 1 Jun 2024 18:24:22 +0200 Subject: feat: Add refs page UI now it is a broken state. I'll all pages working first so I can better style it later. --- pkg/git/git.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'pkg/git') diff --git a/pkg/git/git.go b/pkg/git/git.go index 80c0e46..7ef23f7 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -6,6 +6,7 @@ import ( "io" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" ) @@ -54,6 +55,7 @@ func (g *GitRepository) Commits() ([]*object.Commit, error) { if err != nil { return nil, err } + ref, err := repo.Head() if err != nil { return nil, errors.Join(MissingHeadErr, err) @@ -81,3 +83,49 @@ func (g *GitRepository) Commits() ([]*object.Commit, error) { return commits, nil } + +func (g *GitRepository) Tags() ([]*object.Tag, error) { + repo, err := git.PlainOpen(g.path) + if err != nil { + return nil, err + } + + ti, err := repo.TagObjects() + if err != nil { + return nil, err + } + + tags := []*object.Tag{} + err = ti.ForEach(func(t *object.Tag) error { + tags = append(tags, t) + return nil + }) + if err != nil { + return nil, err + } + + return tags, nil +} + +func (g *GitRepository) Branches() ([]*plumbing.Reference, error) { + repo, err := git.PlainOpen(g.path) + if err != nil { + return nil, err + } + + bs, err := repo.Branches() + if err != nil { + return nil, err + } + + branches := []*plumbing.Reference{} + err = bs.ForEach(func(ref *plumbing.Reference) error { + branches = append(branches, ref) + return nil + }) + if err != nil { + return nil, err + } + + return branches, nil +} -- cgit v1.2.3