From e7707392b8a5ebcb55999443c1d6fc42aed95477 Mon Sep 17 00:00:00 2001 From: Aniket Jhariya Date: Thu, 18 Jun 2026 12:32:35 +0000 Subject: [PATCH] Adds: prompt to allow empty commit messages --- pkg/commands/git_commands/commit.go | 4 +++ pkg/commands/git_commands/commit_test.go | 22 ++++++++++++++++ pkg/gui/controllers/helpers/commits_helper.go | 25 +++++++++++++++++-- pkg/i18n/english.go | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 6abf272b3e7..e4343af16b8 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -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 } diff --git a/pkg/commands/git_commands/commit_test.go b/pkg/commands/git_commands/commit_test.go index 25966c06f72..416748eb324 100644 --- a/pkg/commands/git_commands/commit_test.go +++ b/pkg/commands/git_commands/commit_test.go @@ -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 { diff --git a/pkg/gui/controllers/helpers/commits_helper.go b/pkg/gui/controllers/helpers/commits_helper.go index 5e50ba7b26d..960defbcd03 100644 --- a/pkg/gui/controllers/helpers/commits_helper.go +++ b/pkg/gui/controllers/helpers/commits_helper.go @@ -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) diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 20d0d5ff64e..19dede2b316 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -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",