From e5b09f34e060c87598e22bca9a5b676c3907df80 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 24 Jun 2025 17:22:58 +0200 Subject: [PATCH] Show tag information for selected tag --- pkg/commands/git_commands/tag.go | 17 ++++++++++++ pkg/gui/controllers/tags_controller.go | 37 +++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/tag.go b/pkg/commands/git_commands/tag.go index 8b19409aa..d32f669b3 100644 --- a/pkg/commands/git_commands/tag.go +++ b/pkg/commands/git_commands/tag.go @@ -57,3 +57,20 @@ func (self *TagCommands) Push(task gocui.Task, remoteName string, tagName string return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).Run() } + +// Return info about an annotated tag in the format: +// +// Tagger: tagger name +// 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() +} diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go index 5ce674d91..784d2cc8f 100644 --- a/pkg/gui/controllers/tags_controller.go +++ b/pkg/gui/controllers/tags_controller.go @@ -1,11 +1,16 @@ package controllers import ( + "fmt" + "strings" + "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "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/utils" + "github.com/samber/lo" ) type TagsController struct { @@ -96,7 +101,8 @@ func (self *TagsController) GetOnRenderToMain() func() { task = types.NewRenderStringTask("No tags") } else { 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{ @@ -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 { self.c.LogAction(self.c.Tr.Actions.CheckoutTag) if err := self.c.Helpers().Refs.CheckoutRef(tag.FullRefName(), types.CheckoutRefOptions{}); err != nil {