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:
@ -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 <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()
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user