1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-02 23:27:32 +02:00

show tag message

This commit is contained in:
Jesse Duffield 2023-02-20 18:19:02 +11:00
parent 9e2a3a87dd
commit 39c56553b3
4 changed files with 30 additions and 19 deletions

View File

@ -1,6 +1,8 @@
package git_commands
import (
"regexp"
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@ -26,16 +28,26 @@ func NewTagLoader(
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
// get remote branches, sorted by creation date (descending)
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
tagsOutput, err := self.cmd.New(`git tag --list --sort=-creatordate`).DontLog().RunWithOutput()
tagsOutput, err := self.cmd.New(`git tag --list -n --sort=-creatordate`).DontLog().RunWithOutput()
if err != nil {
return nil, err
}
split := utils.SplitLines(tagsOutput)
tags := slices.Map(split, func(tagName string) *models.Tag {
lineRegex := regexp.MustCompile(`^([^\s]+)(\s+)?(.*)$`)
tags := slices.Map(split, func(line string) *models.Tag {
matches := lineRegex.FindStringSubmatch(line)
tagName := matches[1]
message := ""
if len(matches) > 3 {
message = matches[3]
}
return &models.Tag{
Name: tagName,
Name: tagName,
Message: message,
}
})

View File

@ -9,12 +9,9 @@ import (
"github.com/stretchr/testify/assert"
)
const tagsOutput = `v0.34
v0.33
v0.32.2
v0.32.1
v0.32
testtag
const tagsOutput = `tag1 this is my message
tag2
tag3 this is my other message
`
func TestGetTags(t *testing.T) {
@ -29,21 +26,18 @@ func TestGetTags(t *testing.T) {
{
testName: "should return no tags if there are none",
runner: oscommands.NewFakeRunner(t).
Expect(`git tag --list --sort=-creatordate`, "", nil),
Expect(`git tag --list -n --sort=-creatordate`, "", nil),
expectedTags: []*models.Tag{},
expectedError: nil,
},
{
testName: "should return tags if present",
runner: oscommands.NewFakeRunner(t).
Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil),
Expect(`git tag --list -n --sort=-creatordate`, tagsOutput, nil),
expectedTags: []*models.Tag{
{Name: "v0.34"},
{Name: "v0.33"},
{Name: "v0.32.2"},
{Name: "v0.32.1"},
{Name: "v0.32"},
{Name: "testtag"},
{Name: "tag1", Message: "this is my message"},
{Name: "tag2", Message: ""},
{Name: "tag3", Message: "this is my other message"},
},
expectedError: nil,
},

View File

@ -3,6 +3,9 @@ package models
// Tag : A git tag
type Tag struct {
Name string
// this is either the first line of the message of an annotated tag, or the
// first line of a commit message for a lightweight tag
Message string
}
func (t *Tag) FullRefName() string {
@ -22,5 +25,5 @@ func (t *Tag) ID() string {
}
func (t *Tag) Description() string {
return "tag " + t.Name
return t.Message
}

View File

@ -4,6 +4,7 @@ import (
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/theme"
)
@ -24,6 +25,7 @@ func getTagDisplayStrings(t *models.Tag, diffed bool) []string {
if icons.IsIconEnabled() {
res = append(res, textStyle.Sprint(icons.IconForTag(t)))
}
res = append(res, textStyle.Sprint(t.Name))
descriptionColor := style.FgYellow
res = append(res, textStyle.Sprint(t.Name), descriptionColor.Sprint(t.Description()))
return res
}