2018-08-14 11:05:26 +02:00
|
|
|
package gui
|
|
|
|
|
2018-08-14 14:12:07 +02:00
|
|
|
import (
|
2019-02-24 00:42:24 +02:00
|
|
|
"os/exec"
|
2018-09-05 12:42:11 +02:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2018-08-14 14:12:07 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2020-10-04 02:00:48 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2018-08-14 14:12:07 +02:00
|
|
|
)
|
2018-08-14 11:05:26 +02:00
|
|
|
|
2019-02-24 00:42:24 +02:00
|
|
|
// runSyncOrAsyncCommand takes the output of a command that may have returned
|
|
|
|
// either no error, an error, or a subprocess to execute, and if a subprocess
|
2021-04-02 12:30:39 +02:00
|
|
|
// needs to be run, it runs it
|
2019-03-23 03:16:55 +02:00
|
|
|
func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) (bool, error) {
|
2018-08-14 11:05:26 +02:00
|
|
|
if err != nil {
|
2021-04-02 12:30:39 +02:00
|
|
|
return false, gui.surfaceError(err)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2021-04-08 05:07:54 +02:00
|
|
|
if sub == nil {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
err = gui.runSubprocessWithSuspense(sub)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-03-23 03:16:55 +02:00
|
|
|
return true, nil
|
2019-02-24 00:42:24 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitConfirm() error {
|
2021-04-04 15:51:59 +02:00
|
|
|
message := gui.trimmedContent(gui.Views.CommitMessage)
|
2019-02-24 00:42:24 +02:00
|
|
|
if message == "" {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
|
2019-02-24 00:42:24 +02:00
|
|
|
}
|
2019-04-13 05:34:12 +02:00
|
|
|
flags := ""
|
2020-10-03 06:54:55 +02:00
|
|
|
skipHookPrefix := gui.Config.GetUserConfig().Git.SkipHookPrefix
|
2019-04-13 05:34:12 +02:00
|
|
|
if skipHookPrefix != "" && strings.HasPrefix(message, skipHookPrefix) {
|
|
|
|
flags = "--no-verify"
|
|
|
|
}
|
|
|
|
ok, err := gui.runSyncOrAsyncCommand(gui.GitCommand.Commit(message, flags))
|
2019-03-23 03:16:55 +02:00
|
|
|
if err != nil {
|
2019-02-24 00:42:24 +02:00
|
|
|
return err
|
|
|
|
}
|
2021-04-08 05:07:54 +02:00
|
|
|
|
|
|
|
_ = gui.returnFromContext()
|
|
|
|
|
2019-03-23 03:16:55 +02:00
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
2019-02-24 00:42:24 +02:00
|
|
|
|
2021-04-04 15:51:59 +02:00
|
|
|
gui.clearEditorView(gui.Views.CommitMessage)
|
2020-03-27 10:12:15 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitClose() error {
|
2020-08-16 05:58:29 +02:00
|
|
|
return gui.returnFromContext()
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-16 05:58:29 +02:00
|
|
|
func (gui *Gui) handleCommitMessageFocused() error {
|
2020-10-04 02:00:48 +02:00
|
|
|
message := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.CommitMessageConfirm,
|
|
|
|
map[string]string{
|
2018-08-15 09:15:31 +02:00
|
|
|
"keyBindClose": "esc",
|
|
|
|
"keyBindConfirm": "enter",
|
2020-07-21 23:15:33 +02:00
|
|
|
"keyBindNewLine": "tab",
|
2018-08-15 09:15:31 +02:00
|
|
|
},
|
|
|
|
)
|
2020-10-04 02:00:48 +02:00
|
|
|
|
2021-04-04 16:31:52 +02:00
|
|
|
gui.renderString(gui.Views.Options, message)
|
2020-03-09 02:34:10 +02:00
|
|
|
return nil
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2018-09-05 12:42:11 +02:00
|
|
|
|
|
|
|
func (gui *Gui) getBufferLength(view *gocui.View) string {
|
|
|
|
return " " + strconv.Itoa(strings.Count(view.Buffer(), "")-1) + " "
|
|
|
|
}
|
2018-09-05 15:02:13 +02:00
|
|
|
|
2018-11-30 02:47:14 +02:00
|
|
|
// RenderCommitLength is a function.
|
2018-09-05 15:02:13 +02:00
|
|
|
func (gui *Gui) RenderCommitLength() {
|
2020-10-03 06:54:55 +02:00
|
|
|
if !gui.Config.GetUserConfig().Gui.CommitLength.Show {
|
2018-09-05 15:02:13 +02:00
|
|
|
return
|
|
|
|
}
|
2021-04-04 15:51:59 +02:00
|
|
|
|
|
|
|
gui.Views.CommitMessage.Subtitle = gui.getBufferLength(gui.Views.CommitMessage)
|
2018-09-05 15:02:13 +02:00
|
|
|
}
|