Skip to content

Commit 75ee875

Browse files
authored
Show GPG error before entering commit editor when rewording non-latest commits (#4660)
- **PR Description** When GPG signing is enabled but overrideGpg is false, attempting to reword a non-latest commit would show the "Feature not vailable for users using GPG" error only after the user had already entered the commit message. Now the error is displayed immediately when attempting to start the reword operation, before opening the editor. Closes #4611
2 parents ef6f96b + 9e05e4d commit 75ee875

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pkg/commands/git_commands/rebase.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func NewRebaseCommands(
3535
}
3636

3737
func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, summary string, description string) error {
38+
// This check is currently unreachable (handled in LocalCommitsController.reword),
39+
// but kept as a safeguard in case this method is used elsewhere.
3840
if self.config.NeedsGpgSubprocessForCommit() {
3941
return errors.New(self.Tr.DisabledForGPG)
4042
}

pkg/gui/controllers/local_commits_controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ func (self *LocalCommitsController) fixup(selectedCommits []*models.Commit, star
343343
}
344344

345345
func (self *LocalCommitsController) reword(commit *models.Commit) error {
346+
commitIdx := self.context().GetSelectedLineIdx()
347+
if self.c.Git().Config.NeedsGpgSubprocessForCommit() && !self.isHeadCommit(commitIdx) {
348+
return errors.New(self.c.Tr.DisabledForGPG)
349+
}
346350
commitMessage, err := self.c.Git().Commit.GetCommitMessage(commit.Hash())
347351
if err != nil {
348352
return err
@@ -352,7 +356,7 @@ func (self *LocalCommitsController) reword(commit *models.Commit) error {
352356
}
353357
self.c.Helpers().Commits.OpenCommitMessagePanel(
354358
&helpers.OpenCommitMessagePanelOpts{
355-
CommitIndex: self.context().GetSelectedLineIdx(),
359+
CommitIndex: commitIdx,
356360
InitialMessage: commitMessage,
357361
SummaryTitle: self.c.Tr.Actions.RewordCommit,
358362
DescriptionTitle: self.c.Tr.CommitDescriptionTitle,

0 commit comments

Comments
 (0)