From 9e05e4d8101524bf6759dd7448cb1b6a86c9ca57 Mon Sep 17 00:00:00 2001 From: Mostafa Khaled Date: Mon, 23 Jun 2025 23:52:31 +0300 Subject: [PATCH] fix: show GPG error before entering commit editor Closes #4611 --- pkg/commands/git_commands/rebase.go | 2 ++ pkg/gui/controllers/local_commits_controller.go | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index cd7f4af11..f6302fc28 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -35,6 +35,8 @@ func NewRebaseCommands( } func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, summary string, description string) error { + // This check is currently unreachable (handled in LocalCommitsController.reword), + // but kept as a safeguard in case this method is used elsewhere. if self.config.NeedsGpgSubprocessForCommit() { return errors.New(self.Tr.DisabledForGPG) } diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 321db56c9..b4e18fcde 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -343,6 +343,10 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star } func (self *LocalCommitsController) reword(commit *models.Commit) error { + commitIdx := self.context().GetSelectedLineIdx() + if self.c.Git().Config.NeedsGpgSubprocessForCommit() && !self.isHeadCommit(commitIdx) { + return errors.New(self.c.Tr.DisabledForGPG) + } commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Hash()) if err != nil { return err @@ -352,7 +356,7 @@ func (self *LocalCommitsController) reword(commit *models.Commit) error { } self.c.Helpers().Commits.OpenCommitMessagePanel( &helpers.OpenCommitMessagePanelOpts{ - CommitIndex: self.context().GetSelectedLineIdx(), + CommitIndex: commitIdx, InitialMessage: commitMessage, SummaryTitle: self.c.Tr.Actions.RewordCommit, DescriptionTitle: self.c.Tr.CommitDescriptionTitle,