You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_tag_gogit.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. //go:build gogit
  6. // +build gogit
  7. package git
  8. import (
  9. "strings"
  10. "github.com/go-git/go-git/v5/plumbing"
  11. )
  12. // IsTagExist returns true if given tag exists in the repository.
  13. func (repo *Repository) IsTagExist(name string) bool {
  14. _, err := repo.gogitRepo.Reference(plumbing.ReferenceName(TagPrefix+name), true)
  15. return err == nil
  16. }
  17. // GetTags returns all tags of the repository.
  18. func (repo *Repository) GetTags() ([]string, error) {
  19. var tagNames []string
  20. tags, err := repo.gogitRepo.Tags()
  21. if err != nil {
  22. return nil, err
  23. }
  24. _ = tags.ForEach(func(tag *plumbing.Reference) error {
  25. tagNames = append(tagNames, strings.TrimPrefix(tag.Name().String(), TagPrefix))
  26. return nil
  27. })
  28. // Reverse order
  29. for i := 0; i < len(tagNames)/2; i++ {
  30. j := len(tagNames) - i - 1
  31. tagNames[i], tagNames[j] = tagNames[j], tagNames[i]
  32. }
  33. return tagNames, nil
  34. }