Skip to content

Commit 0aea7f1

Browse files
lunnytechknowlogick
authored andcommitted
fix get tag list (go-gitea#143)
1 parent fbe468c commit 0aea7f1

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

repo_tag.go

+4-12
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,18 @@ func (repo *Repository) GetTagInfos() ([]*Tag, error) {
103103
}
104104

105105
tagNames := strings.Split(stdout, "\n")
106-
var tags []*Tag
106+
var tags = make([]*Tag, 0, len(tagNames))
107107
for _, tagName := range tagNames {
108108
tagName = strings.TrimSpace(tagName)
109109
if len(tagName) == 0 {
110110
continue
111111
}
112-
commitID, err := NewCommand("rev-parse", tagName).RunInDir(repo.Path)
113-
if err != nil {
114-
return nil, err
115-
}
116-
commit, err := repo.GetCommit(commitID)
112+
113+
tag, err := repo.GetTag(tagName)
117114
if err != nil {
118115
return nil, err
119116
}
120-
tags = append(tags, &Tag{
121-
Name: tagName,
122-
Message: commit.Message(),
123-
Object: commit.ID,
124-
Tagger: commit.Author,
125-
})
117+
tags = append(tags, tag)
126118
}
127119
sortTagsByTime(tags)
128120
return tags, nil

repo_tag_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
import (
8+
"path/filepath"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestRepository_GetTags(t *testing.T) {
15+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
16+
bareRepo1, err := OpenRepository(bareRepo1Path)
17+
assert.NoError(t, err)
18+
19+
tags, err := bareRepo1.GetTagInfos()
20+
assert.NoError(t, err)
21+
assert.Len(t, tags, 1)
22+
assert.EqualValues(t, "test", tags[0].Name)
23+
assert.EqualValues(t, "3ad28a9149a2864384548f3d17ed7f38014c9e8a", tags[0].ID.String())
24+
assert.EqualValues(t, "commit", tags[0].Type)
25+
}

0 commit comments

Comments
 (0)