Skip to content

Commit e5b09f3

Browse files
committed
Show tag information for selected tag
1 parent b12b104 commit e5b09f3

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

pkg/commands/git_commands/tag.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ func (self *TagCommands) Push(task gocui.Task, remoteName string, tagName string
5757

5858
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
5959
}
60+
61+
// Return info about an annotated tag in the format:
62+
//
63+
// Tagger: tagger name <tagger email>
64+
// TaggerDate: tagger date
65+
//
66+
// Tag message
67+
//
68+
// Should only be called for annotated tags.
69+
func (self *TagCommands) ShowAnnotationInfo(tagName string) (string, error) {
70+
cmdArgs := NewGitCmd("for-each-ref").
71+
Arg("--format=Tagger: %(taggername) %(taggeremail)%0aTaggerDate: %(taggerdate)%0a%0a%(contents)").
72+
Arg("refs/tags/" + tagName).
73+
ToArgv()
74+
75+
return self.cmd.New(cmdArgs).RunWithOutput()
76+
}

pkg/gui/controllers/tags_controller.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package controllers
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
"github.com/jesseduffield/gocui"
58
"github.com/jesseduffield/lazygit/pkg/commands/models"
69
"github.com/jesseduffield/lazygit/pkg/gui/context"
10+
"github.com/jesseduffield/lazygit/pkg/gui/style"
711
"github.com/jesseduffield/lazygit/pkg/gui/types"
812
"github.com/jesseduffield/lazygit/pkg/utils"
13+
"github.com/samber/lo"
914
)
1015

1116
type TagsController struct {
@@ -96,7 +101,8 @@ func (self *TagsController) GetOnRenderToMain() func() {
96101
task = types.NewRenderStringTask("No tags")
97102
} else {
98103
cmdObj := self.c.Git().Branch.GetGraphCmdObj(tag.FullRefName())
99-
task = types.NewRunCommandTask(cmdObj.GetCmd())
104+
prefix := self.getTagInfo(tag) + "\n\n---\n\n"
105+
task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
100106
}
101107

102108
self.c.RenderToMainViews(types.RefreshMainOpts{
@@ -110,6 +116,35 @@ func (self *TagsController) GetOnRenderToMain() func() {
110116
}
111117
}
112118

119+
func (self *TagsController) getTagInfo(tag *models.Tag) string {
120+
if tag.IsAnnotated {
121+
info := fmt.Sprintf("%s: %s", self.c.Tr.AnnotatedTag, style.AttrBold.Sprint(style.FgYellow.Sprint(tag.Name)))
122+
output, err := self.c.Git().Tag.ShowAnnotationInfo(tag.Name)
123+
if err == nil {
124+
info += "\n\n" + strings.TrimRight(filterOutPgpSignature(output), "\n")
125+
}
126+
return info
127+
}
128+
129+
return fmt.Sprintf("%s: %s", self.c.Tr.LightweightTag, style.AttrBold.Sprint(style.FgYellow.Sprint(tag.Name)))
130+
}
131+
132+
func filterOutPgpSignature(output string) string {
133+
lines := strings.Split(output, "\n")
134+
inPgpSignature := false
135+
filteredLines := lo.Filter(lines, func(line string, _ int) bool {
136+
if line == "-----END PGP SIGNATURE-----" {
137+
inPgpSignature = false
138+
return false
139+
}
140+
if line == "-----BEGIN PGP SIGNATURE-----" {
141+
inPgpSignature = true
142+
}
143+
return !inPgpSignature
144+
})
145+
return strings.Join(filteredLines, "\n")
146+
}
147+
113148
func (self *TagsController) checkout(tag *models.Tag) error {
114149
self.c.LogAction(self.c.Tr.Actions.CheckoutTag)
115150
if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil {

0 commit comments

Comments
 (0)