1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-03 00:57:52 +02:00

Show tag information for selected tag

This commit is contained in:
Stefan Haller
2025-06-24 17:22:58 +02:00
parent b12b1040c3
commit e5b09f34e0
2 changed files with 53 additions and 1 deletions

View File

@ -57,3 +57,20 @@ func (self *TagCommands) Push(task gocui.Task, remoteName string, tagName string
return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run() return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run()
} }
// Return info about an annotated tag in the format:
//
// Tagger: tagger name <tagger email>
// TaggerDate: tagger date
//
// Tag message
//
// Should only be called for annotated tags.
func (self *TagCommands) ShowAnnotationInfo(tagName string) (string, error) {
cmdArgs := NewGitCmd("for-each-ref").
Arg("--format=Tagger: %(taggername) %(taggeremail)%0aTaggerDate: %(taggerdate)%0a%0a%(contents)").
Arg("refs/tags/" + tagName).
ToArgv()
return self.cmd.New(cmdArgs).RunWithOutput()
}

View File

@ -1,11 +1,16 @@
package controllers package controllers
import ( import (
"fmt"
"strings"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
) )
type TagsController struct { type TagsController struct {
@ -96,7 +101,8 @@ func (self *TagsController) GetOnRenderToMain() func() {
task = types.NewRenderStringTask("No tags") task = types.NewRenderStringTask("No tags")
} else { } else {
cmdObj := self.c.Git().Branch.GetGraphCmdObj(tag.FullRefName()) cmdObj := self.c.Git().Branch.GetGraphCmdObj(tag.FullRefName())
task = types.NewRunCommandTask(cmdObj.GetCmd()) prefix := self.getTagInfo(tag) + "\n\n---\n\n"
task = types.NewRunCommandTaskWithPrefix(cmdObj.GetCmd(), prefix)
} }
self.c.RenderToMainViews(types.RefreshMainOpts{ self.c.RenderToMainViews(types.RefreshMainOpts{
@ -110,6 +116,35 @@ func (self *TagsController) GetOnRenderToMain() func() {
} }
} }
func (self *TagsController) getTagInfo(tag *models.Tag) string {
if tag.IsAnnotated {
info := fmt.Sprintf("%s: %s", self.c.Tr.AnnotatedTag, style.AttrBold.Sprint(style.FgYellow.Sprint(tag.Name)))
output, err := self.c.Git().Tag.ShowAnnotationInfo(tag.Name)
if err == nil {
info += "\n\n" + strings.TrimRight(filterOutPgpSignature(output), "\n")
}
return info
}
return fmt.Sprintf("%s: %s", self.c.Tr.LightweightTag, style.AttrBold.Sprint(style.FgYellow.Sprint(tag.Name)))
}
func filterOutPgpSignature(output string) string {
lines := strings.Split(output, "\n")
inPgpSignature := false
filteredLines := lo.Filter(lines, func(line string, _ int) bool {
if line == "-----END PGP SIGNATURE-----" {
inPgpSignature = false
return false
}
if line == "-----BEGIN PGP SIGNATURE-----" {
inPgpSignature = true
}
return !inPgpSignature
})
return strings.Join(filteredLines, "\n")
}
func (self *TagsController) checkout(tag *models.Tag) error { func (self *TagsController) checkout(tag *models.Tag) error {
self.c.LogAction(self.c.Tr.Actions.CheckoutTag) self.c.LogAction(self.c.Tr.Actions.CheckoutTag)
if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil { if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil {