1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/commit_message_panel.go
Mark Sagi-Kazar fdf0d4a2c3 implement signoff
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
2021-12-25 12:01:55 +11:00

66 lines
1.9 KiB
Go

package gui
import (
"strconv"
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/utils"
)
func (gui *Gui) handleCommitConfirm() error {
message := strings.TrimSpace(gui.Views.CommitMessage.TextArea.GetContent())
if message == "" {
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
}
flags := []string{}
skipHookPrefix := gui.Config.GetUserConfig().Git.SkipHookPrefix
if skipHookPrefix != "" && strings.HasPrefix(message, skipHookPrefix) {
flags = append(flags, "--no-verify")
}
if gui.Config.GetUserConfig().Git.Commit.SignOff {
flags = append(flags, "--signoff")
}
cmdStr := gui.GitCommand.CommitCmdStr(message, strings.Join(flags, " "))
gui.OnRunCommand(oscommands.NewCmdLogEntry(cmdStr, gui.Tr.Spans.Commit, true))
_ = gui.returnFromContext()
return gui.withGpgHandling(cmdStr, gui.Tr.CommittingStatus, func() error {
gui.Views.CommitMessage.ClearTextArea()
return nil
})
}
func (gui *Gui) handleCommitClose() error {
return gui.returnFromContext()
}
func (gui *Gui) handleCommitMessageFocused() error {
message := utils.ResolvePlaceholderString(
gui.Tr.CommitMessageConfirm,
map[string]string{
"keyBindClose": gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.Return),
"keyBindConfirm": gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.Confirm),
"keyBindNewLine": gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline),
},
)
gui.renderString(gui.Views.Options, message)
return nil
}
func (gui *Gui) getBufferLength(view *gocui.View) string {
return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " "
}
// RenderCommitLength is a function.
func (gui *Gui) RenderCommitLength() {
if !gui.Config.GetUserConfig().Gui.CommitLength.Show {
return
}
gui.Views.CommitMessage.Subtitle = gui.getBufferLength(gui.Views.CommitMessage)
}