forked from jesseduffield/lazygit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cea24c2
commit 3c13229
Showing
14 changed files
with
390 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package commands | ||
|
||
import ( | ||
"regexp" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/jesseduffield/lazygit/pkg/utils" | ||
) | ||
|
||
const semverRegex = `v?((\d+\.?)+)([^\d]?.*)` | ||
|
||
func (c *GitCommand) GetTags() ([]*Tag, error) { | ||
// get remote branches | ||
remoteBranchesStr, err := c.OSCommand.RunCommandWithOutput("git tag --list") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
content := utils.TrimTrailingNewline(remoteBranchesStr) | ||
if content == "" { | ||
return nil, nil | ||
} | ||
|
||
split := strings.Split(content, "\n") | ||
|
||
// first step is to get our remotes from go-git | ||
tags := make([]*Tag, len(split)) | ||
for i, tagName := range split { | ||
|
||
tags[i] = &Tag{ | ||
Name: tagName, | ||
} | ||
} | ||
|
||
// now lets sort our tags by name numerically | ||
re := regexp.MustCompile(semverRegex) | ||
|
||
// 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 { | ||
a := tags[i].Name | ||
b := 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 mustConvertToInt(numbersA[k]) < mustConvertToInt(numbersB[k]) { | ||
return true | ||
} | ||
if mustConvertToInt(numbersA[k]) > mustConvertToInt(numbersB[k]) { | ||
return false | ||
} | ||
k++ | ||
} | ||
|
||
return strings.ToLower(matchA[3]) < strings.ToLower(matchB[3]) | ||
} | ||
|
||
return strings.ToLower(a) < strings.ToLower(b) | ||
}) | ||
|
||
return tags, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package commands | ||
|
||
// Tag : A git tag | ||
type Tag struct { | ||
Name string | ||
} | ||
|
||
// GetDisplayStrings returns the display string of a remote | ||
func (r *Tag) GetDisplayStrings(isFocused bool) []string { | ||
return []string{r.Name} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.