1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-31 22:22:14 +02:00

Add command to reset the commit author from the commits panel.

This commit is contained in:
Jens Pfeifle 2022-04-22 16:01:30 +02:00 committed by Jesse Duffield
parent 8247089e53
commit 7c573a5bea
5 changed files with 53 additions and 0 deletions
pkg
commands/git_commands
config
gui/controllers
i18n

@ -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)).

@ -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 {

@ -242,6 +242,7 @@ type KeybindingCommitsConfig struct {
MoveDownCommit string `yaml:"moveDownCommit"`
MoveUpCommit string `yaml:"moveUpCommit"`
AmendToCommit string `yaml:"amendToCommit"`
ResetCommitAuthor string `yaml:"resetCommitAuthor"`
PickCommit string `yaml:"pickCommit"`
RevertCommit string `yaml:"revertCommit"`
CherryPickCopy string `yaml:"cherryPickCopy"`
@ -513,6 +514,7 @@ func GetDefaultConfig() *UserConfig {
MoveDownCommit: "<c-j>",
MoveUpCommit: "<c-k>",
AmendToCommit: "A",
ResetCommitAuthor: "a",
PickCommit: "p",
RevertCommit: "t",
CherryPickCopy: "c",

@ -121,6 +121,11 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
Handler: self.checkSelected(self.amendTo),
Description: self.c.Tr.LcAmendToCommit,
},
{
Key: opts.GetKey(opts.Config.Commits.ResetCommitAuthor),
Handler: self.checkSelected(self.resetAuthor),
Description: self.c.Tr.LcResetCommitAuthor,
},
{
Key: opts.GetKey(opts.Config.Commits.RevertCommit),
Handler: self.checkSelected(self.revert),
@ -418,6 +423,21 @@ func (self *LocalCommitsController) amendTo(commit *models.Commit) error {
})
}
func (self *LocalCommitsController) resetAuthor(commit *models.Commit) error {
return self.c.Confirm(types.ConfirmOpts{
Title: self.c.Tr.LcResetCommitAuthor,
Prompt: self.c.Tr.SureResetCommitAuthor,
HandleConfirm: func() error {
self.c.LogAction(self.c.Tr.Actions.ResetCommitAuthor)
if err := self.git.Rebase.ResetCommitAuthor(self.model.Commits, self.context().GetSelectedLineIdx()); err != nil {
return self.c.Error(err)
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
},
})
}
func (self *LocalCommitsController) revert(commit *models.Commit) error {
if commit.IsMerge() {
return self.createRevertMergeCommitMenu(commit)

@ -98,6 +98,8 @@ type TranslationSet struct {
LcMoveUpCommit string
LcEditCommit string
LcAmendToCommit string
LcResetCommitAuthor string
SureResetCommitAuthor string
LcRenameCommitEditor string
NoCommitsThisBranch string
Error string
@ -529,6 +531,7 @@ type Actions struct {
DropCommit string
EditCommit string
AmendCommit string
ResetCommitAuthor string
RevertCommit string
CreateFixupCommit string
SquashAllAboveFixupCommits string
@ -713,6 +716,8 @@ func EnglishTranslationSet() TranslationSet {
LcMoveUpCommit: "move commit up one",
LcEditCommit: "edit commit",
LcAmendToCommit: "amend commit with staged changes",
LcResetCommitAuthor: "reset commit author",
SureResetCommitAuthor: "Are you sure you want to reset the author of this commit?",
LcRenameCommitEditor: "reword commit with editor",
Error: "Error",
LcSelectHunk: "select hunk",
@ -1125,6 +1130,7 @@ func EnglishTranslationSet() TranslationSet {
DropCommit: "Drop commit",
EditCommit: "Edit commit",
AmendCommit: "Amend commit",
ResetCommitAuthor: "Reset commit author",
RevertCommit: "Revert commit",
CreateFixupCommit: "Create fixup commit",
SquashAllAboveFixupCommits: "Squash all above fixup commits",