Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

fix get tag list #143

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions repo_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,18 @@ func (repo *Repository) GetTagInfos() ([]*Tag, error) {
}

tagNames := strings.Split(stdout, "\n")
var tags []*Tag
var tags = make([]*Tag, 0, len(tagNames))
for _, tagName := range tagNames {
tagName = strings.TrimSpace(tagName)
if len(tagName) == 0 {
continue
}
commitID, err := NewCommand("rev-parse", tagName).RunInDir(repo.Path)
if err != nil {
return nil, err
}
commit, err := repo.GetCommit(commitID)

tag, err := repo.GetTag(tagName)
if err != nil {
return nil, err
}
tags = append(tags, &Tag{
Name: tagName,
Message: commit.Message(),
Object: commit.ID,
Tagger: commit.Author,
})
tags = append(tags, tag)
}
sortTagsByTime(tags)
return tags, nil
Expand Down
25 changes: 25 additions & 0 deletions repo_tag_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package git

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestRepository_GetTags(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)

tags, err := bareRepo1.GetTagInfos()
assert.NoError(t, err)
assert.Len(t, tags, 1)
assert.EqualValues(t, "test", tags[0].Name)
assert.EqualValues(t, "3ad28a9149a2864384548f3d17ed7f38014c9e8a", tags[0].ID.String())
assert.EqualValues(t, "commit", tags[0].Type)
}