Skip to content

Commit

Permalink
Allow rewording for last commit using GPG
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed Aug 10, 2024
1 parent 8e76dc9 commit c5dc791
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 3 additions & 5 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/git_commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/gui/controllers/local_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit c5dc791

Please sign in to comment.