Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/commands/git_commands/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 23 additions & 2 deletions pkg/gui/controllers/helpers/commits_helper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helpers

import (
"errors"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type TranslationSet struct {
CannotMoveCommitsNoUnpushedCommits string
NoBranchesThisRepo string
CommitWithoutMessageErr string
CommitWithoutMessagePrompt string
Close string
CloseCancel string
Confirm string
Expand Down Expand Up @@ -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",
Expand Down