mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Adds: prompt to allow empty commit messages
This commit is contained in:
parent
69004ce208
commit
e7707392b8
|
|
@ -135,6 +135,10 @@ func (self *CommitCommands) commitMessageArgs(summary string, description string
|
|||
args = append(args, "-m", description)
|
||||
}
|
||||
|
||||
if strings.TrimSpace(summary) == "" && strings.TrimSpace(description) == "" {
|
||||
args = append(args, "--allow-empty-message")
|
||||
}
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ func TestCommitRewordCommit(t *testing.T) {
|
|||
"test",
|
||||
"line 2\nline 3",
|
||||
},
|
||||
{
|
||||
"Empty reword",
|
||||
oscommands.NewFakeRunner(t).ExpectGitArgs([]string{"commit", "--allow-empty", "--amend", "--only", "-m", "", "--allow-empty-message"}, "", nil),
|
||||
"",
|
||||
"",
|
||||
},
|
||||
}
|
||||
for _, s := range scenarios {
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
|
|
@ -118,6 +124,22 @@ func TestCommitCommitCmdObj(t *testing.T) {
|
|||
configSkipHookPrefix: "WIP",
|
||||
expectedArgs: []string{"commit", "--no-verify", "--signoff", "-m", "WIP: test"},
|
||||
},
|
||||
{
|
||||
testName: "Commit with empty message",
|
||||
summary: "",
|
||||
forceSkipHooks: false,
|
||||
configSignoff: false,
|
||||
configSkipHookPrefix: "",
|
||||
expectedArgs: []string{"commit", "-m", "", "--allow-empty-message"},
|
||||
},
|
||||
{
|
||||
testName: "Commit with whitespace-only message",
|
||||
summary: " ",
|
||||
forceSkipHooks: false,
|
||||
configSignoff: false,
|
||||
configSkipHookPrefix: "",
|
||||
expectedArgs: []string{"commit", "-m", " ", "--allow-empty-message"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package helpers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -183,7 +182,29 @@ func (self *CommitsHelper) HandleCommitConfirm() error {
|
|||
summary, description := self.getCommitSummary(), self.getCommitDescription()
|
||||
|
||||
if strings.TrimSpace(summary) == "" {
|
||||
return errors.New(self.c.Tr.CommitWithoutMessageErr)
|
||||
self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.Confirm,
|
||||
Prompt: self.c.Tr.CommitWithoutMessagePrompt,
|
||||
HideCancel: true,
|
||||
Items: []*types.MenuItem{
|
||||
{
|
||||
Label: self.c.Tr.Confirm,
|
||||
OnPress: func() error {
|
||||
self.CloseCommitMessagePanel()
|
||||
return self.c.Contexts().CommitMessage.OnConfirm(summary, description)
|
||||
},
|
||||
Keys: menuKey('y'),
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.Close,
|
||||
OnPress: func() error {
|
||||
return nil
|
||||
},
|
||||
Keys: menuKey('n'),
|
||||
},
|
||||
},
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
err := self.c.Contexts().CommitMessage.OnConfirm(summary, description)
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ type TranslationSet struct {
|
|||
CannotMoveCommitsNoUnpushedCommits string
|
||||
NoBranchesThisRepo string
|
||||
CommitWithoutMessageErr string
|
||||
CommitWithoutMessagePrompt string
|
||||
Close string
|
||||
CloseCancel string
|
||||
Confirm string
|
||||
|
|
@ -1280,6 +1281,7 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
CannotMoveCommitsNoUnpushedCommits: "There are no unpushed commits to move to a new branch",
|
||||
NoBranchesThisRepo: "No branches for this repo",
|
||||
CommitWithoutMessageErr: "You cannot commit without a commit message",
|
||||
CommitWithoutMessagePrompt: "You have not entered a commit message. Commit anyway with an empty message?",
|
||||
Close: "Close",
|
||||
CloseCancel: "Close/Cancel",
|
||||
Confirm: "Confirm",
|
||||
|
|
|
|||
Loading…
Reference in a new issue