mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +02:00
show tag message
This commit is contained in:
parent
9e2a3a87dd
commit
39c56553b3
@ -1,6 +1,8 @@
|
|||||||
package git_commands
|
package git_commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
@ -26,16 +28,26 @@ func NewTagLoader(
|
|||||||
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
func (self *TagLoader) GetTags() ([]*models.Tag, error) {
|
||||||
// get remote branches, sorted by creation date (descending)
|
// get remote branches, sorted by creation date (descending)
|
||||||
// see: https://git-scm.com/docs/git-tag#Documentation/git-tag.txt---sortltkeygt
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
split := utils.SplitLines(tagsOutput)
|
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{
|
return &models.Tag{
|
||||||
Name: tagName,
|
Name: tagName,
|
||||||
|
Message: message,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -9,12 +9,9 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const tagsOutput = `v0.34
|
const tagsOutput = `tag1 this is my message
|
||||||
v0.33
|
tag2
|
||||||
v0.32.2
|
tag3 this is my other message
|
||||||
v0.32.1
|
|
||||||
v0.32
|
|
||||||
testtag
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestGetTags(t *testing.T) {
|
func TestGetTags(t *testing.T) {
|
||||||
@ -29,21 +26,18 @@ func TestGetTags(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testName: "should return no tags if there are none",
|
testName: "should return no tags if there are none",
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
Expect(`git tag --list --sort=-creatordate`, "", nil),
|
Expect(`git tag --list -n --sort=-creatordate`, "", nil),
|
||||||
expectedTags: []*models.Tag{},
|
expectedTags: []*models.Tag{},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testName: "should return tags if present",
|
testName: "should return tags if present",
|
||||||
runner: oscommands.NewFakeRunner(t).
|
runner: oscommands.NewFakeRunner(t).
|
||||||
Expect(`git tag --list --sort=-creatordate`, tagsOutput, nil),
|
Expect(`git tag --list -n --sort=-creatordate`, tagsOutput, nil),
|
||||||
expectedTags: []*models.Tag{
|
expectedTags: []*models.Tag{
|
||||||
{Name: "v0.34"},
|
{Name: "tag1", Message: "this is my message"},
|
||||||
{Name: "v0.33"},
|
{Name: "tag2", Message: ""},
|
||||||
{Name: "v0.32.2"},
|
{Name: "tag3", Message: "this is my other message"},
|
||||||
{Name: "v0.32.1"},
|
|
||||||
{Name: "v0.32"},
|
|
||||||
{Name: "testtag"},
|
|
||||||
},
|
},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
|
@ -3,6 +3,9 @@ package models
|
|||||||
// Tag : A git tag
|
// Tag : A git tag
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
Name string
|
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 {
|
func (t *Tag) FullRefName() string {
|
||||||
@ -22,5 +25,5 @@ func (t *Tag) ID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tag) Description() string {
|
func (t *Tag) Description() string {
|
||||||
return "tag " + t.Name
|
return t.Message
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ func getTagDisplayStrings(t *models.Tag, diffed bool) []string {
|
|||||||
if icons.IsIconEnabled() {
|
if icons.IsIconEnabled() {
|
||||||
res = append(res, textStyle.Sprint(icons.IconForTag(t)))
|
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
|
return res
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user