Skip to content

Commit 1210a64

Browse files
authored
Fix amending commits whose commit message is empty (#4732)
- **PR Description** When the commit message is empty, the `--amend` command will produce an error. Solution: Add the `--allow-empty-message` option.
2 parents 9625ee8 + 0451a16 commit 1210a64

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/commands/git_commands/commit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func NewCommitCommands(gitCommon *GitCommon) *CommitCommands {
2323
// ResetAuthor resets the author of the topmost commit
2424
func (self *CommitCommands) ResetAuthor() error {
2525
cmdArgs := NewGitCmd("commit").
26-
Arg("--allow-empty", "--only", "--no-edit", "--amend", "--reset-author").
26+
Arg("--allow-empty", "--allow-empty-message", "--only", "--no-edit", "--amend", "--reset-author").
2727
ToArgv()
2828

2929
return self.cmd.New(cmdArgs).Run()
@@ -32,7 +32,7 @@ func (self *CommitCommands) ResetAuthor() error {
3232
// Sets the commit's author to the supplied value. Value is expected to be of the form 'Name <Email>'
3333
func (self *CommitCommands) SetAuthor(value string) error {
3434
cmdArgs := NewGitCmd("commit").
35-
Arg("--allow-empty", "--only", "--no-edit", "--amend", "--author="+value).
35+
Arg("--allow-empty", "--allow-empty-message", "--only", "--no-edit", "--amend", "--author="+value).
3636
ToArgv()
3737

3838
return self.cmd.New(cmdArgs).Run()
@@ -247,7 +247,7 @@ func (self *CommitCommands) AmendHead() error {
247247

248248
func (self *CommitCommands) AmendHeadCmdObj() *oscommands.CmdObj {
249249
cmdArgs := NewGitCmd("commit").
250-
Arg("--amend", "--no-edit", "--allow-empty").
250+
Arg("--amend", "--no-edit", "--allow-empty", "--allow-empty-message").
251251
ToArgv()
252252

253253
return self.cmd.New(cmdArgs)

pkg/commands/git_commands/rebase_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestRebaseDiscardOldFileChanges(t *testing.T) {
141141
ExpectGitArgs([]string{"rebase", "--interactive", "--autostash", "--keep-empty", "--no-autosquash", "--rebase-merges", "abcdef"}, "", nil).
142142
ExpectGitArgs([]string{"cat-file", "-e", "HEAD^:test999.txt"}, "", nil).
143143
ExpectGitArgs([]string{"checkout", "HEAD^", "--", "test999.txt"}, "", nil).
144-
ExpectGitArgs([]string{"commit", "--amend", "--no-edit", "--allow-empty"}, "", nil).
144+
ExpectGitArgs([]string{"commit", "--amend", "--no-edit", "--allow-empty", "--allow-empty-message"}, "", nil).
145145
ExpectGitArgs([]string{"rebase", "--continue"}, "", nil),
146146
test: func(err error) {
147147
assert.NoError(t, err)

0 commit comments

Comments
 (0)