mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
add commit message controller
This commit is contained in:
parent
120078f011
commit
d991d74b06
11 changed files with 217 additions and 129 deletions
79
pkg/gui/controllers/commit_message_controller.go
Normal file
79
pkg/gui/controllers/commit_message_controller.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
)
|
||||
|
||||
type CommitMessageController struct {
|
||||
baseController
|
||||
*controllerCommon
|
||||
|
||||
getCommitMessage func() string
|
||||
onCommitAttempt func(message string)
|
||||
onCommitSuccess func()
|
||||
}
|
||||
|
||||
var _ types.IController = &CommitMessageController{}
|
||||
|
||||
func NewCommitMessageController(
|
||||
common *controllerCommon,
|
||||
getCommitMessage func() string,
|
||||
onCommitAttempt func(message string),
|
||||
onCommitSuccess func(),
|
||||
) *CommitMessageController {
|
||||
return &CommitMessageController{
|
||||
baseController: baseController{},
|
||||
controllerCommon: common,
|
||||
|
||||
getCommitMessage: getCommitMessage,
|
||||
onCommitAttempt: onCommitAttempt,
|
||||
onCommitSuccess: onCommitSuccess,
|
||||
}
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
||||
bindings := []*types.Binding{
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.SubmitEditorText),
|
||||
Handler: self.handleCommitConfirm,
|
||||
},
|
||||
{
|
||||
Key: opts.GetKey(opts.Config.Universal.Return),
|
||||
Handler: self.handleCommitClose,
|
||||
},
|
||||
}
|
||||
|
||||
return bindings
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) Context() types.Context {
|
||||
return self.context()
|
||||
}
|
||||
|
||||
// this method is pointless in this context but I'm keeping it consistent
|
||||
// with other contexts so that when generics arrive it's easier to refactor
|
||||
func (self *CommitMessageController) context() types.Context {
|
||||
return self.contexts.CommitMessage
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) handleCommitConfirm() error {
|
||||
message := self.getCommitMessage()
|
||||
self.onCommitAttempt(message)
|
||||
|
||||
if message == "" {
|
||||
return self.c.ErrorMsg(self.c.Tr.CommitWithoutMessageErr)
|
||||
}
|
||||
|
||||
cmdObj := self.git.Commit.CommitCmdObj(message)
|
||||
self.c.LogAction(self.c.Tr.Actions.Commit)
|
||||
|
||||
_ = self.c.PopContext()
|
||||
return self.helpers.GPG.WithGpgHandling(cmdObj, self.c.Tr.CommittingStatus, func() error {
|
||||
self.onCommitSuccess()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (self *CommitMessageController) handleCommitClose() error {
|
||||
return self.c.PopContext()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue