mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 20:37:52 +01:00
Merge pull request #525 from linquize/tag-sort-reverse
sort tags in descending order by version number
This commit is contained in:
commit
b694cc88e4
@ -22,6 +22,9 @@ func (repo *Repository) IsTagExist(tagName string) bool {
|
|||||||
|
|
||||||
// GetTags returns all tags of given repository.
|
// GetTags returns all tags of given repository.
|
||||||
func (repo *Repository) GetTags() ([]string, error) {
|
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")
|
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New(stderr)
|
return nil, errors.New(stderr)
|
||||||
@ -30,6 +33,15 @@ func (repo *Repository) GetTags() ([]string, error) {
|
|||||||
return tags[:len(tags)-1], nil
|
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 {
|
func (repo *Repository) CreateTag(tagName, idStr string) error {
|
||||||
_, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", tagName, idStr)
|
_, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", tagName, idStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,6 +74,10 @@ func (v *Version) LessThan(that *Version) bool {
|
|||||||
return v.Compare(that) < 0
|
return v.Compare(that) < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *Version) AtLeast(that *Version) bool {
|
||||||
|
return v.Compare(that) >= 0
|
||||||
|
}
|
||||||
|
|
||||||
// GetVersion returns current Git version installed.
|
// GetVersion returns current Git version installed.
|
||||||
func GetVersion() (*Version, error) {
|
func GetVersion() (*Version, error) {
|
||||||
if gitVer != nil {
|
if gitVer != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user