diff --git a/pkg/commands/loading_tags.go b/pkg/commands/loading_tags.go index 8bd66c936..71704f9c0 100644 --- a/pkg/commands/loading_tags.go +++ b/pkg/commands/loading_tags.go @@ -1,28 +1,16 @@ package commands import ( - "regexp" - "sort" - "strconv" "strings" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/utils" ) -const semverRegex = `v?((\d+\.?)+)([^\d]?.*)` - -func convertToInt(s string) int { - i, err := strconv.Atoi(s) - if err != nil { - return 0 - } - return i -} - func (c *GitCommand) GetTags() ([]*models.Tag, error) { - // get remote branches - remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput(`git tag --list`) + // get remote branches, sorted by creation date (descending) + // see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt + remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput(`git tag --list --sort=-creatordate`) if err != nil { return nil, err } @@ -37,59 +25,10 @@ func (c *GitCommand) GetTags() ([]*models.Tag, error) { // first step is to get our remotes from go-git tags := make([]*models.Tag, len(split)) for i, tagName := range split { - tags[i] = &models.Tag{ Name: tagName, } } - // now lets sort our tags by name numerically - re := regexp.MustCompile(semverRegex) - - sortAsc := c.Config.GetUserConfig().Gui.SortTagsAscending - // the reason this is complicated is because we're both sorting alphabetically - // and when we're dealing with semver strings - sort.Slice(tags, func(i, j int) bool { - var a, b string - if sortAsc { - a = tags[i].Name - b = tags[j].Name - } else { - b = tags[i].Name - a = tags[j].Name - } - - matchA := re.FindStringSubmatch(a) - matchB := re.FindStringSubmatch(b) - - if len(matchA) > 0 && len(matchB) > 0 { - numbersA := strings.Split(matchA[1], ".") - numbersB := strings.Split(matchB[1], ".") - k := 0 - for { - if len(numbersA) == k && len(numbersB) == k { - break - } - if len(numbersA) == k { - return true - } - if len(numbersB) == k { - return false - } - if convertToInt(numbersA[k]) < convertToInt(numbersB[k]) { - return true - } - if convertToInt(numbersA[k]) > convertToInt(numbersB[k]) { - return false - } - k++ - } - - return strings.ToLower(matchA[3]) < strings.ToLower(matchB[3]) - } - - return strings.ToLower(a) < strings.ToLower(b) - }) - return tags, nil } diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 074dcbc63..cf193011b 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -39,7 +39,6 @@ type GuiConfig struct { ShowRandomTip bool `yaml:"showRandomTip"` ShowCommandLog bool `yaml:"showCommandLog"` CommandLogSize int `yaml:"commandLogSize"` - SortTagsAscending bool `yaml:"sortTagsAscending"` } type ThemeConfig struct { @@ -308,7 +307,6 @@ func GetDefaultConfig() *UserConfig { ShowFileTree: false, ShowRandomTip: true, CommandLogSize: 8, - SortTagsAscending: false, }, Git: GitConfig{ Paging: PagingConfig{