1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-08 22:36:49 +02:00

Allow GPG reword for last commit (#3815)

- **PR Description**
This PR fixes #3806, which is only for the last commit.
Would be good if this could be extended to commits older than head.
This commit is contained in:
Stefan Haller
2024-08-16 13:11:17 +02:00
committed by GitHub
4 changed files with 16 additions and 8 deletions

View File

@ -117,7 +117,7 @@ func (self *CommitCommands) CommitInEditorWithMessageFileCmdObj(tmpMessageFile s
} }
// RewordLastCommit rewords the topmost commit with the given message // 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) messageArgs := self.commitMessageArgs(summary, description)
cmdArgs := NewGitCmd("commit"). cmdArgs := NewGitCmd("commit").
@ -125,7 +125,7 @@ func (self *CommitCommands) RewordLastCommit(summary string, description string)
Arg(messageArgs...). Arg(messageArgs...).
ToArgv() ToArgv()
return self.cmd.New(cmdArgs).Run() return self.cmd.New(cmdArgs)
} }
func (self *CommitCommands) commitMessageArgs(summary string, description string) []string { func (self *CommitCommands) commitMessageArgs(summary string, description string) []string {

View File

@ -33,7 +33,7 @@ func TestCommitRewordCommit(t *testing.T) {
t.Run(s.testName, func(t *testing.T) { t.Run(s.testName, func(t *testing.T) {
instance := buildCommitCommands(commonDeps{runner: s.runner}) instance := buildCommitCommands(commonDeps{runner: s.runner})
assert.NoError(t, instance.RewordLastCommit(s.summary, s.description)) assert.NoError(t, instance.RewordLastCommit(s.summary, s.description).Run())
s.runner.CheckForMissingCalls() s.runner.CheckForMissingCalls()
}) })
} }

View File

@ -35,9 +35,8 @@ func NewRebaseCommands(
} }
func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, summary string, description string) error { func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, summary string, description string) error {
if models.IsHeadCommit(commits, index) { if self.config.UsingGpg() {
// we've selected the top commit so no rebase is required return errors.New(self.Tr.DisabledForGPG)
return self.commit.RewordLastCommit(summary, description)
} }
err := self.BeginInteractiveRebaseForCommit(commits, index, false) err := self.BeginInteractiveRebaseForCommit(commits, index, false)
@ -46,7 +45,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 // 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 { if err != nil {
return err return err
} }

View File

@ -400,7 +400,16 @@ func (self *LocalCommitsController) switchFromCommitMessagePanelToEditor(filepat
} }
func (self *LocalCommitsController) handleReword(summary string, description string) error { 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
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, nil)
} else {
err = self.c.Git().Rebase.RewordCommit(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), summary, description)
}
if err != nil { if err != nil {
return err return err
} }