diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-01 18:24:22 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-01 18:24:22 +0200 |
commit | f1643ffcbd543cacfe9ab5e46eafdd0c39cd47fd (patch) | |
tree | a24d3cbb625f642c25cdc14124b8971fa9bfeb04 /pkg/git/git.go | |
parent | 4ea63e98cc999ab05d1ac98b64875d7413e86972 (diff) | |
download | cerrado-f1643ffcbd543cacfe9ab5e46eafdd0c39cd47fd.tar.gz cerrado-f1643ffcbd543cacfe9ab5e46eafdd0c39cd47fd.tar.bz2 cerrado-f1643ffcbd543cacfe9ab5e46eafdd0c39cd47fd.zip |
feat: Add refs page
UI now it is a broken state. I'll all pages working first so I can
better style it later.
Diffstat (limited to 'pkg/git/git.go')
-rw-r--r-- | pkg/git/git.go | 48 |
1 files changed, 48 insertions, 0 deletions
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 +} |