mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
retain commit message if precommit hook fails
This commit is contained in:
parent
b99305c909
commit
a2c780b085
@ -11,17 +11,18 @@ import (
|
|||||||
// runSyncOrAsyncCommand takes the output of a command that may have returned
|
// 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
|
// either no error, an error, or a subprocess to execute, and if a subprocess
|
||||||
// needs to be set on the gui object, it does so, and then returns the error
|
// needs to be set on the gui object, it does so, and then returns the error
|
||||||
func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) error {
|
// the bool returned tells us whether the calling code should continue
|
||||||
|
func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) (bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != gui.Errors.ErrSubProcess {
|
if err != gui.Errors.ErrSubProcess {
|
||||||
return gui.createErrorPanel(gui.g, err.Error())
|
return false, gui.createErrorPanel(gui.g, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sub != nil {
|
if sub != nil {
|
||||||
gui.SubProcess = sub
|
gui.SubProcess = sub
|
||||||
return gui.Errors.ErrSubProcess
|
return false, gui.Errors.ErrSubProcess
|
||||||
}
|
}
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
|
||||||
@ -29,9 +30,13 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
|
|||||||
if message == "" {
|
if message == "" {
|
||||||
return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr"))
|
return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr"))
|
||||||
}
|
}
|
||||||
if err := gui.runSyncOrAsyncCommand(gui.GitCommand.Commit(message)); err != nil {
|
ok, err := gui.runSyncOrAsyncCommand(gui.GitCommand.Commit(message))
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
v.Clear()
|
v.Clear()
|
||||||
_ = v.SetCursor(0, 0)
|
_ = v.SetCursor(0, 0)
|
||||||
|
@ -328,9 +328,13 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro
|
|||||||
question := gui.Tr.SLocalize("SureToAmend")
|
question := gui.Tr.SLocalize("SureToAmend")
|
||||||
|
|
||||||
return gui.createConfirmationPanel(g, filesView, title, question, func(g *gocui.Gui, v *gocui.View) error {
|
return gui.createConfirmationPanel(g, filesView, title, question, func(g *gocui.Gui, v *gocui.View) error {
|
||||||
if err := gui.runSyncOrAsyncCommand(gui.GitCommand.AmendHead()); err != nil {
|
ok, err := gui.runSyncOrAsyncCommand(gui.GitCommand.AmendHead())
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return gui.refreshSidePanels(g)
|
return gui.refreshSidePanels(g)
|
||||||
}, nil)
|
}, nil)
|
||||||
@ -355,7 +359,8 @@ func (gui *Gui) PrepareSubProcess(g *gocui.Gui, commands ...string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) editFile(filename string) error {
|
func (gui *Gui) editFile(filename string) error {
|
||||||
return gui.runSyncOrAsyncCommand(gui.OSCommand.EditFile(filename))
|
_, err := gui.runSyncOrAsyncCommand(gui.OSCommand.EditFile(filename))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user