mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-28 02:07:09 -04:00
Show tag information for selected tag
This commit is contained in:
@@ -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