// 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)
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 {
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 {