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

Commit

Permalink
fix get tag list (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored and techknowlogick committed Feb 7, 2019
1 parent fbe468c commit 0aea7f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
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)
}

0 comments on commit 0aea7f1

Please sign in to comment.