diff options
author | 无闻 <joe2010xtmf@163.com> | 2014-10-05 00:08:24 -0400 |
---|---|---|
committer | 无闻 <joe2010xtmf@163.com> | 2014-10-05 00:08:24 -0400 |
commit | b694cc88e4370381c08632913aaea149a2a796df (patch) | |
tree | a515c87586fadb3f476d547926d7b4464d298c56 | |
parent | 263d4093260707c6249eecb52ad52a0205e61351 (diff) | |
parent | 67c44b7d27a15dd415651ccb9a2ad486a3738183 (diff) | |
download | gitea-b694cc88e4370381c08632913aaea149a2a796df.tar.gz gitea-b694cc88e4370381c08632913aaea149a2a796df.zip |
Merge pull request #525 from linquize/tag-sort-reverse
sort tags in descending order by version number
-rw-r--r-- | modules/git/repo_tag.go | 12 | ||||
-rw-r--r-- | modules/git/version.go | 4 |
2 files changed, 16 insertions, 0 deletions
diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index 77ae3db007..ed994d48ae 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -22,6 +22,9 @@ func (repo *Repository) IsTagExist(tagName string) bool { // GetTags returns all tags of given repository. func (repo *Repository) GetTags() ([]string, error) { + if gitVer.AtLeast(MustParseVersion("2.0.0")) { + return repo.getTagsReversed() + } stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l") if err != nil { return nil, errors.New(stderr) @@ -30,6 +33,15 @@ func (repo *Repository) GetTags() ([]string, error) { return tags[:len(tags)-1], nil } +func (repo *Repository) getTagsReversed() ([]string, error) { + stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l", "--sort=-v:refname") + if err != nil { + return nil, errors.New(stderr) + } + tags := strings.Split(stdout, "\n") + return tags[:len(tags)-1], nil +} + func (repo *Repository) CreateTag(tagName, idStr string) error { _, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", tagName, idStr) if err != nil { diff --git a/modules/git/version.go b/modules/git/version.go index 9908d11e20..b535521ec4 100644 --- a/modules/git/version.go +++ b/modules/git/version.go @@ -74,6 +74,10 @@ func (v *Version) LessThan(that *Version) bool { return v.Compare(that) < 0 } +func (v *Version) AtLeast(that *Version) bool { + return v.Compare(that) >= 0 +} + // GetVersion returns current Git version installed. func GetVersion() (*Version, error) { if gitVer != nil { |