From 0451a1651060130b1ebfa75ff5b0c63d99f84aac Mon Sep 17 00:00:00 2001 From: aidancz Date: Sun, 13 Jul 2025 14:19:11 +0800 Subject: [PATCH] Fix `--amend` when the commit message is empty --- pkg/commands/git_commands/commit.go | 6 +++--- pkg/commands/git_commands/rebase_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index f021a90bf..11b75c8f0 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -23,7 +23,7 @@ func NewCommitCommands(gitCommon *GitCommon) *CommitCommands { // ResetAuthor resets the author of the topmost commit func (self *CommitCommands) ResetAuthor() error { cmdArgs := NewGitCmd("commit"). - Arg("--allow-empty", "--only", "--no-edit", "--amend", "--reset-author"). + Arg("--allow-empty", "--allow-empty-message", "--only", "--no-edit", "--amend", "--reset-author"). ToArgv() return self.cmd.New(cmdArgs).Run() @@ -32,7 +32,7 @@ func (self *CommitCommands) ResetAuthor() error { // Sets the commit's author to the supplied value. Value is expected to be of the form 'Name ' func (self *CommitCommands) SetAuthor(value string) error { cmdArgs := NewGitCmd("commit"). - Arg("--allow-empty", "--only", "--no-edit", "--amend", "--author="+value). + Arg("--allow-empty", "--allow-empty-message", "--only", "--no-edit", "--amend", "--author="+value). ToArgv() return self.cmd.New(cmdArgs).Run() @@ -247,7 +247,7 @@ func (self *CommitCommands) AmendHead() error { func (self *CommitCommands) AmendHeadCmdObj() *oscommands.CmdObj { cmdArgs := NewGitCmd("commit"). - Arg("--amend", "--no-edit", "--allow-empty"). + Arg("--amend", "--no-edit", "--allow-empty", "--allow-empty-message"). ToArgv() return self.cmd.New(cmdArgs) diff --git a/pkg/commands/git_commands/rebase_test.go b/pkg/commands/git_commands/rebase_test.go index de55739ce..40385bf09 100644 --- a/pkg/commands/git_commands/rebase_test.go +++ b/pkg/commands/git_commands/rebase_test.go @@ -141,7 +141,7 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) { ExpectGitArgs([]string{"rebase", "--interactive", "--autostash", "--keep-empty", "--no-autosquash", "--rebase-merges", "abcdef"}, "", nil). ExpectGitArgs([]string{"cat-file", "-e", "HEAD^:test999.txt"}, "", nil). ExpectGitArgs([]string{"checkout", "HEAD^", "--", "test999.txt"}, "", nil). - ExpectGitArgs([]string{"commit", "--amend", "--no-edit", "--allow-empty"}, "", nil). + ExpectGitArgs([]string{"commit", "--amend", "--no-edit", "--allow-empty", "--allow-empty-message"}, "", nil). ExpectGitArgs([]string{"rebase", "--continue"}, "", nil), test: func(err error) { assert.NoError(t, err)