diff options
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 +} |