mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-23 00:39:13 +02:00
remember the message if commit fails
In case a commit fails, e.g. because a pre-commit hook returns an error, lazygit will now remember the commit message and will suggest it during the next commit (e.g. after fixing the error of the pre-commit hook).
This commit is contained in:
committed by
Jesse Duffield
parent
0d3e5e6a1d
commit
beedc2553d
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
func (gui *Gui) handleCommitConfirm() error {
|
func (gui *Gui) handleCommitConfirm() error {
|
||||||
message := strings.TrimSpace(gui.Views.CommitMessage.TextArea.GetContent())
|
message := strings.TrimSpace(gui.Views.CommitMessage.TextArea.GetContent())
|
||||||
|
gui.State.messageFailedCommit = message
|
||||||
if message == "" {
|
if message == "" {
|
||||||
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
|
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
|
||||||
}
|
}
|
||||||
@ -29,6 +30,7 @@ func (gui *Gui) handleCommitConfirm() error {
|
|||||||
_ = gui.returnFromContext()
|
_ = gui.returnFromContext()
|
||||||
return gui.withGpgHandling(cmdObj, gui.Tr.CommittingStatus, func() error {
|
return gui.withGpgHandling(cmdObj, gui.Tr.CommittingStatus, func() error {
|
||||||
gui.Views.CommitMessage.ClearTextArea()
|
gui.Views.CommitMessage.ClearTextArea()
|
||||||
|
gui.State.messageFailedCommit = ""
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -386,18 +386,24 @@ func (gui *Gui) handleCommitPress() error {
|
|||||||
return gui.promptToStageAllAndRetry(gui.handleCommitPress)
|
return gui.promptToStageAllAndRetry(gui.handleCommitPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
commitPrefixConfig := gui.commitPrefixConfigForRepo()
|
if len(gui.State.messageFailedCommit) > 0 {
|
||||||
if commitPrefixConfig != nil {
|
|
||||||
prefixPattern := commitPrefixConfig.Pattern
|
|
||||||
prefixReplace := commitPrefixConfig.Replace
|
|
||||||
rgx, err := regexp.Compile(prefixPattern)
|
|
||||||
if err != nil {
|
|
||||||
return gui.createErrorPanel(fmt.Sprintf("%s: %s", gui.Tr.LcCommitPrefixPatternError, err.Error()))
|
|
||||||
}
|
|
||||||
prefix := rgx.ReplaceAllString(gui.getCheckedOutBranch().Name, prefixReplace)
|
|
||||||
gui.Views.CommitMessage.ClearTextArea()
|
gui.Views.CommitMessage.ClearTextArea()
|
||||||
gui.Views.CommitMessage.TextArea.TypeString(prefix)
|
gui.Views.CommitMessage.TextArea.TypeString(gui.State.messageFailedCommit)
|
||||||
gui.render()
|
gui.Views.CommitMessage.RenderTextArea()
|
||||||
|
} else {
|
||||||
|
commitPrefixConfig := gui.commitPrefixConfigForRepo()
|
||||||
|
if commitPrefixConfig != nil {
|
||||||
|
prefixPattern := commitPrefixConfig.Pattern
|
||||||
|
prefixReplace := commitPrefixConfig.Replace
|
||||||
|
rgx, err := regexp.Compile(prefixPattern)
|
||||||
|
if err != nil {
|
||||||
|
return gui.createErrorPanel(fmt.Sprintf("%s: %s", gui.Tr.LcCommitPrefixPatternError, err.Error()))
|
||||||
|
}
|
||||||
|
prefix := rgx.ReplaceAllString(gui.getCheckedOutBranch().Name, prefixReplace)
|
||||||
|
gui.Views.CommitMessage.ClearTextArea()
|
||||||
|
gui.Views.CommitMessage.TextArea.TypeString(prefix)
|
||||||
|
gui.Views.CommitMessage.RenderTextArea()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
|
@ -346,6 +346,9 @@ type guiState struct {
|
|||||||
|
|
||||||
// for displaying suggestions while typing in a file name
|
// for displaying suggestions while typing in a file name
|
||||||
FilesTrie *patricia.Trie
|
FilesTrie *patricia.Trie
|
||||||
|
|
||||||
|
// this is the message of the last failed commit attempt
|
||||||
|
messageFailedCommit string
|
||||||
}
|
}
|
||||||
|
|
||||||
// reuseState determines if we pull the repo state from our repo state map or
|
// reuseState determines if we pull the repo state from our repo state map or
|
||||||
|
Reference in New Issue
Block a user