Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow GPG reword for last commit #3815

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/commands/git_commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ 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").
Arg("--allow-empty", "--amend", "--only").
Arg(messageArgs...).
ToArgv()

return self.cmd.New(cmdArgs).Run()
return self.cmd.New(cmdArgs)
}

func (self *CommitCommands) commitMessageArgs(summary string, description string) []string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestCommitRewordCommit(t *testing.T) {
t.Run(s.testName, func(t *testing.T) {
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()
})
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/commands/git_commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ func NewRebaseCommands(
}

func (self *RebaseCommands) RewordCommit(commits []*models.Commit, index int, summary string, description string) error {
if models.IsHeadCommit(commits, index) {
// we've selected the top commit so no rebase is required
return self.commit.RewordLastCommit(summary, description)
if self.config.UsingGpg() {
return errors.New(self.Tr.DisabledForGPG)
}

err := self.BeginInteractiveRebaseForCommit(commits, index, false)
Expand All @@ -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
err = self.commit.RewordLastCommit(summary, description)
err = self.commit.RewordLastCommit(summary, description).Run()
if err != nil {
return err
}
Expand Down
11 changes: 10 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,16 @@ 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

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 {
return err
}
Expand Down
Loading