aboutsummaryrefslogtreecommitdiff
path: root/pkg/git
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-07-07 20:28:42 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2024-07-07 21:44:29 +0200
commit44bc8e4078a09857ad86691a83e7ba7d4e3a69c4 (patch)
tree6788cafeaac286d381cc69e1917dab6ae58d1f85 /pkg/git
parent8dff852753a1c4a708fd87e3cbb0f4844803aa95 (diff)
downloadcerrado-44bc8e4078a09857ad86691a83e7ba7d4e3a69c4.tar.gz
cerrado-44bc8e4078a09857ad86691a83e7ba7d4e3a69c4.tar.bz2
cerrado-44bc8e4078a09857ad86691a83e7ba7d4e3a69c4.zip
ref: Simplify path builder code
Diffstat (limited to 'pkg/git')
-rw-r--r--pkg/git/git.go48
1 files changed, 41 insertions, 7 deletions
diff --git a/pkg/git/git.go b/pkg/git/git.go
index 6b58d35..7341c1b 100644
--- a/pkg/git/git.go
+++ b/pkg/git/git.go
@@ -38,6 +38,11 @@ type (
modTime time.Time
isDir bool
}
+
+ TagReference struct {
+ ref *plumbing.Reference
+ tag *object.Tag
+ }
)
func OpenRepository(dir string) (*GitRepository, error) {
@@ -119,18 +124,31 @@ func (g *GitRepository) Head() (*plumbing.Reference, error) {
return g.repository.Head()
}
-func (g *GitRepository) Tags() ([]*plumbing.Reference, error) {
- ti, err := g.repository.Tags()
+func (g *GitRepository) Tags() ([]*TagReference, error) {
+ iter, err := g.repository.Tags()
if err != nil {
return nil, err
}
- tags := []*plumbing.Reference{}
- err = ti.ForEach(func(t *plumbing.Reference) error {
- tags = append(tags, t)
+ tags := make([]*TagReference, 0)
+
+ if err := iter.ForEach(func(ref *plumbing.Reference) error {
+ obj, err := g.repository.TagObject(ref.Hash())
+ switch err {
+ case nil:
+ tags = append(tags, &TagReference{
+ ref: ref,
+ tag: obj,
+ })
+ case plumbing.ErrObjectNotFound:
+ tags = append(tags, &TagReference{
+ ref: ref,
+ })
+ default:
+ return err
+ }
return nil
- })
- if err != nil {
+ }); err != nil {
return nil, err
}
@@ -361,3 +379,19 @@ func (i *infoWrapper) IsDir() bool {
func (i *infoWrapper) Sys() any {
return nil
}
+
+func (t *TagReference) HashString() string {
+ return t.ref.Hash().String()
+}
+
+func (t *TagReference) ShortName() string {
+ return t.ref.Name().Short()
+}
+
+func (t *TagReference) Message() string {
+ if t.tag != nil {
+ return t.tag.Message
+ }
+ return ""
+
+}