diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go index 4153dfeb909..83a7ac1dca4 100644 --- a/pkg/commands/git_commands/commit.go +++ b/pkg/commands/git_commands/commit.go @@ -117,15 +117,13 @@ func (self *CommitCommands) CommitInEditorWithMessageFileCmdObj(tmpMessageFile s } // RewordLastCommit rewords the topmost commit with the given message -func (self *CommitCommands) RewordLastCommit(summary string, description string) error { +func (self *CommitCommands) RewordLastCommit(summary string, description string) oscommands.ICmdObj { messageArgs := self.commitMessageArgs(summary, description) - cmdArgs := NewGitCmd("commit"). + return self.cmd.New(NewGitCmd("commit"). Arg("--allow-empty", "--amend", "--only"). Arg(messageArgs...). - ToArgv() - - return self.cmd.New(cmdArgs).Run() + ToArgv()) } func (self *CommitCommands) commitMessageArgs(summary string, description string) []string { diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index 019d58e3a1f..daea3fbd038 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -41,7 +41,7 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, su if models.IsHeadCommit(commits, index) { // we've selected the top commit so no rebase is required - return self.commit.RewordLastCommit(summary, description) + return self.commit.RewordLastCommit(summary, description).Run() } err := self.BeginInteractiveRebaseForCommit(commits, index, false) @@ -50,7 +50,7 @@ func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, su } // now the selected commit should be our head so we'll amend it with the new message - err = self.commit.RewordLastCommit(summary, description) + err = self.commit.RewordLastCommit(summary, description).Run() if err != nil { return err } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index f95062fdbe3..baec545ee92 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -400,7 +400,18 @@ func (self *LocalCommitsController) switchFromCommitMessagePanelToEditor(filepat } func (self *LocalCommitsController) handleReword(summary string, description string) error { - err := self.c.Git().Rebase.RewordCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), summary, description) + var err error = nil + + if models.IsHeadCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx()) { + // we've selected the top commit so no rebase is required + err = self.c.Helpers().GPG.WithGpgHandling(self.c.Git().Commit.RewordLastCommit(summary, description), + self.c.Tr.CommittingStatus, func() error { + return nil + }) + } else { + err = self.c.Git().Rebase.RewordCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), summary, description) + } + if err != nil { return err }