summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorJens Pfeifle <jens@pfeifle.tech>2022-04-22 16:01:30 +0200
committerJesse Duffield <jessedduffield@gmail.com>2022-05-08 13:29:56 +1000
commit7c573a5bea37cefd4ab036ac23d9dd45cd4059bd (patch)
treef1fe6f4dceeb1f14a7add963dacf0e969b4c4ef7 /pkg/commands
parent8247089e53e851a76147205d72766a264bb00a97 (diff)
Add command to reset the commit author from the commits panel.
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/commit.go5
-rw-r--r--pkg/commands/git_commands/rebase.go20
2 files changed, 25 insertions, 0 deletions
diff --git a/pkg/commands/git_commands/commit.go b/pkg/commands/git_commands/commit.go
index 2422a2600..4cbc3033c 100644
--- a/pkg/commands/git_commands/commit.go
+++ b/pkg/commands/git_commands/commit.go
@@ -23,6 +23,11 @@ func (self *CommitCommands) RewordLastCommit(message string) error {
return self.cmd.New("git commit --allow-empty --amend --only -m " + self.cmd.Quote(message)).Run()
}
+// Reset the author of the topmost commit.
+func (self *CommitCommands) ResetAuthor() error {
+ return self.cmd.New("git commit --allow-empty --no-edit --amend --reset-author").Run()
+}
+
// ResetToCommit reset to commit
func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error {
return self.cmd.New(fmt.Sprintf("git reset --%s %s", strength, sha)).
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go
index e69c8b1bd..d94060f2a 100644
--- a/pkg/commands/git_commands/rebase.go
+++ b/pkg/commands/git_commands/rebase.go
@@ -62,6 +62,26 @@ func (self *RebaseCommands) RewordCommitInEditor(commits []*models.Commit, index
return self.PrepareInteractiveRebaseCommand(sha, todo, false), nil
}
+func (self *RebaseCommands) ResetCommitAuthor(commits []*models.Commit, index int) error {
+ if index == 0 {
+ // we've selected the top commit so no rebase is required
+ return self.commit.ResetAuthor()
+ }
+
+ err := self.BeginInteractiveRebaseForCommit(commits, index)
+ if err != nil {
+ return err
+ }
+
+ // now the selected commit should be our head so we'll amend it with the new author
+ err = self.commit.ResetAuthor()
+ if err != nil {
+ return err
+ }
+
+ return self.ContinueRebase()
+}
+
func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) error {
// we must ensure that we have at least two commits after the selected one
if len(commits) <= index+2 {