mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-17 21:18:31 +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:
parent
0d3e5e6a1d
commit
beedc2553d
@ -10,6 +10,7 @@ import (
|
||||
|
||||
func (gui *Gui) handleCommitConfirm() error {
|
||||
message := strings.TrimSpace(gui.Views.CommitMessage.TextArea.GetContent())
|
||||
gui.State.messageFailedCommit = message
|
||||
if message == "" {
|
||||
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
|
||||
}
|
||||
@ -29,6 +30,7 @@ func (gui *Gui) handleCommitConfirm() error {
|
||||
_ = gui.returnFromContext()
|
||||
return gui.withGpgHandling(cmdObj, gui.Tr.CommittingStatus, func() error {
|
||||
gui.Views.CommitMessage.ClearTextArea()
|
||||
gui.State.messageFailedCommit = ""
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
@ -386,18 +386,24 @@ func (gui *Gui) handleCommitPress() error {
|
||||
return gui.promptToStageAllAndRetry(gui.handleCommitPress)
|
||||
}
|
||||
|
||||
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)
|
||||
if len(gui.State.messageFailedCommit) > 0 {
|
||||
gui.Views.CommitMessage.ClearTextArea()
|
||||
gui.Views.CommitMessage.TextArea.TypeString(prefix)
|
||||
gui.render()
|
||||
gui.Views.CommitMessage.TextArea.TypeString(gui.State.messageFailedCommit)
|
||||
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 {
|
||||
|
@ -346,6 +346,9 @@ type guiState struct {
|
||||
|
||||
// for displaying suggestions while typing in a file name
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user