summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJakob Kogler <jakob.kogler@gmail.com>2021-12-05 22:33:07 +0100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-07 11:01:42 +1100
commitbeedc2553d7b17ca8ac2827965980a2a6bd9fafb (patch)
tree7ca9bfd888b052ee2414f6527b6bae208ea7f217 /pkg
parent0d3e5e6a1dc7d131cd714a260b4f365380a033c6 (diff)
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).
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/commit_message_panel.go2
-rw-r--r--pkg/gui/files_panel.go28
-rw-r--r--pkg/gui/gui.go3
3 files changed, 22 insertions, 11 deletions
diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go
index 932c1608a..2e3d2edb7 100644
--- a/pkg/gui/commit_message_panel.go
+++ b/pkg/gui/commit_message_panel.go
@@ -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
})
}
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 094060032..ea897f085 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -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 {
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 9b4279f29..08960ff16 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -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