diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-18 09:38:36 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | 3c1322914518168374be02a78cee968cf1d13730 (patch) | |
tree | d31c1064a1101a6081db025328f39789fc3b74c4 /pkg/commands | |
parent | cea24c2cf98c48e187900041d9e3bbeb93596019 (diff) |
add tags panel
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/commit.go | 8 | ||||
-rw-r--r-- | pkg/commands/commit_list_builder.go | 1 | ||||
-rw-r--r-- | pkg/commands/git.go | 18 | ||||
-rw-r--r-- | pkg/commands/loading_tags.go | 78 | ||||
-rw-r--r-- | pkg/commands/tag.go | 11 |
5 files changed, 114 insertions, 2 deletions
diff --git a/pkg/commands/commit.go b/pkg/commands/commit.go index 4102af4c0..5e4633c18 100644 --- a/pkg/commands/commit.go +++ b/pkg/commands/commit.go @@ -1,6 +1,8 @@ package commands import ( + "strings" + "github.com/fatih/color" "github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/utils" @@ -14,6 +16,7 @@ type Commit struct { DisplayString string Action string // one of "", "pick", "edit", "squash", "reword", "drop", "fixup" Copied bool // to know if this commit is ready to be cherry-picked somewhere + Tags []string } // GetDisplayStrings is a function. @@ -52,9 +55,12 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string { } actionString := "" + tagString := "" if c.Action != "" { actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " " + } else if len(c.Tags) > 0 { + tagString = utils.ColoredString(strings.Join(c.Tags, " "), color.FgMagenta) + " " } - return []string{shaColor.Sprint(c.Sha), actionString + defaultColor.Sprint(c.Name)} + return []string{shaColor.Sprint(c.Sha), actionString + tagString + defaultColor.Sprint(c.Name)} } diff --git a/pkg/commands/commit_list_builder.go b/pkg/commands/commit_list_builder.go index aab6de6a3..48ae793b6 100644 --- a/pkg/commands/commit_list_builder.go +++ b/pkg/commands/commit_list_builder.go @@ -78,6 +78,7 @@ func (c *CommitListBuilder) GetCommits() ([]*Commit, error) { Name: strings.Join(splitLine[1:], " "), Status: status, DisplayString: strings.Join(splitLine, " "), + // TODO: add tags here }) } if rebaseMode != "" { diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 76c753940..faa1493db 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -419,7 +419,7 @@ func (c *GitCommand) Push(branchName string, force bool, upstream string, ask fu setUpstreamArg = "--set-upstream " + upstream } - cmd := fmt.Sprintf("git push %s %s", forceFlag, setUpstreamArg) + cmd := fmt.Sprintf("git push --follow-tags %s %s", forceFlag, setUpstreamArg) return c.OSCommand.DetectUnamePass(cmd, ask) } @@ -1099,3 +1099,19 @@ func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) er func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error { return c.OSCommand.RunCommand(fmt.Sprintf("git remote set-url %s %s", remoteName, updatedUrl)) } + +func (c *GitCommand) CreateLightweightTag(tagName string, commitSha string) error { + return c.OSCommand.RunCommand(fmt.Sprintf("git tag %s %s", tagName, commitSha)) +} + +func (c *GitCommand) ShowTag(tagName string) (string, error) { + return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git tag -n99 %s", tagName)) +} + +func (c *GitCommand) DeleteTag(tagName string) error { + return c.OSCommand.RunCommand(fmt.Sprintf("git tag -d %s", tagName)) +} + +func (c *GitCommand) PushTag(remoteName string, tagName string) error { + return c.OSCommand.RunCommand(fmt.Sprintf("git push %s %s", remoteName, tagName)) +} diff --git a/pkg/commands/loading_tags.go b/pkg/commands/loading_tags.go new file mode 100644 index 000000000..75a2d994d --- /dev/null +++ b/pkg/commands/loading_tags.go @@ -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 +} diff --git a/pkg/commands/tag.go b/pkg/commands/tag.go new file mode 100644 index 000000000..99a4a7f0e --- /dev/null +++ b/pkg/commands/tag.go @@ -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} +} |