From 39c56553b36eaa05d6a12bdb66fe612736f92344 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 20 Feb 2023 18:19:02 +1100 Subject: [PATCH] show tag message --- pkg/commands/git_commands/tag_loader.go | 18 +++++++++++++--- pkg/commands/git_commands/tag_loader_test.go | 22 +++++++------------- pkg/commands/models/tag.go | 5 ++++- pkg/gui/presentation/tags.go | 4 +++- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/pkg/commands/git_commands/tag_loader.go b/pkg/commands/git_commands/tag_loader.go index 738283405..2dc5a4f41 100644 --- a/pkg/commands/git_commands/tag_loader.go +++ b/pkg/commands/git_commands/tag_loader.go @@ -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, } }) diff --git a/pkg/commands/git_commands/tag_loader_test.go b/pkg/commands/git_commands/tag_loader_test.go index f8696cafa..61b55d018 100644 --- a/pkg/commands/git_commands/tag_loader_test.go +++ b/pkg/commands/git_commands/tag_loader_test.go @@ -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, }, diff --git a/pkg/commands/models/tag.go b/pkg/commands/models/tag.go index 25d8754f5..ab6076a7a 100644 --- a/pkg/commands/models/tag.go +++ b/pkg/commands/models/tag.go @@ -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 } diff --git a/pkg/gui/presentation/tags.go b/pkg/gui/presentation/tags.go index 2996db18d..944448a8c 100644 --- a/pkg/gui/presentation/tags.go +++ b/pkg/gui/presentation/tags.go @@ -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 }