mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-13 05:15:53 +02:00
Add command to reset the commit author from the commits panel.
This commit is contained in:
parent
8247089e53
commit
7c573a5bea
5 changed files with 53 additions and 0 deletions
|
@ -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()
|
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
|
// ResetToCommit reset to commit
|
||||||
func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error {
|
func (self *CommitCommands) ResetToCommit(sha string, strength string, envVars []string) error {
|
||||||
return self.cmd.New(fmt.Sprintf("git reset --%s %s", strength, sha)).
|
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
|
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 {
|
func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) error {
|
||||||
// we must ensure that we have at least two commits after the selected one
|
// we must ensure that we have at least two commits after the selected one
|
||||||
if len(commits) <= index+2 {
|
if len(commits) <= index+2 {
|
||||||
|
|
|
@ -242,6 +242,7 @@ type KeybindingCommitsConfig struct {
|
||||||
MoveDownCommit string `yaml:"moveDownCommit"`
|
MoveDownCommit string `yaml:"moveDownCommit"`
|
||||||
MoveUpCommit string `yaml:"moveUpCommit"`
|
MoveUpCommit string `yaml:"moveUpCommit"`
|
||||||
AmendToCommit string `yaml:"amendToCommit"`
|
AmendToCommit string `yaml:"amendToCommit"`
|
||||||
|
ResetCommitAuthor string `yaml:"resetCommitAuthor"`
|
||||||
PickCommit string `yaml:"pickCommit"`
|
PickCommit string `yaml:"pickCommit"`
|
||||||
RevertCommit string `yaml:"revertCommit"`
|
RevertCommit string `yaml:"revertCommit"`
|
||||||
CherryPickCopy string `yaml:"cherryPickCopy"`
|
CherryPickCopy string `yaml:"cherryPickCopy"`
|
||||||
|
@ -513,6 +514,7 @@ func GetDefaultConfig() *UserConfig {
|
||||||
MoveDownCommit: "<c-j>",
|
MoveDownCommit: "<c-j>",
|
||||||
MoveUpCommit: "<c-k>",
|
MoveUpCommit: "<c-k>",
|
||||||
AmendToCommit: "A",
|
AmendToCommit: "A",
|
||||||
|
ResetCommitAuthor: "a",
|
||||||
PickCommit: "p",
|
PickCommit: "p",
|
||||||
RevertCommit: "t",
|
RevertCommit: "t",
|
||||||
CherryPickCopy: "c",
|
CherryPickCopy: "c",
|
||||||
|
|
|
@ -121,6 +121,11 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
|
||||||
Handler: self.checkSelected(self.amendTo),
|
Handler: self.checkSelected(self.amendTo),
|
||||||
Description: self.c.Tr.LcAmendToCommit,
|
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),
|
Key: opts.GetKey(opts.Config.Commits.RevertCommit),
|
||||||
Handler: self.checkSelected(self.revert),
|
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 {
|
func (self *LocalCommitsController) revert(commit *models.Commit) error {
|
||||||
if commit.IsMerge() {
|
if commit.IsMerge() {
|
||||||
return self.createRevertMergeCommitMenu(commit)
|
return self.createRevertMergeCommitMenu(commit)
|
||||||
|
|
|
@ -98,6 +98,8 @@ type TranslationSet struct {
|
||||||
LcMoveUpCommit string
|
LcMoveUpCommit string
|
||||||
LcEditCommit string
|
LcEditCommit string
|
||||||
LcAmendToCommit string
|
LcAmendToCommit string
|
||||||
|
LcResetCommitAuthor string
|
||||||
|
SureResetCommitAuthor string
|
||||||
LcRenameCommitEditor string
|
LcRenameCommitEditor string
|
||||||
NoCommitsThisBranch string
|
NoCommitsThisBranch string
|
||||||
Error string
|
Error string
|
||||||
|
@ -529,6 +531,7 @@ type Actions struct {
|
||||||
DropCommit string
|
DropCommit string
|
||||||
EditCommit string
|
EditCommit string
|
||||||
AmendCommit string
|
AmendCommit string
|
||||||
|
ResetCommitAuthor string
|
||||||
RevertCommit string
|
RevertCommit string
|
||||||
CreateFixupCommit string
|
CreateFixupCommit string
|
||||||
SquashAllAboveFixupCommits string
|
SquashAllAboveFixupCommits string
|
||||||
|
@ -713,6 +716,8 @@ func EnglishTranslationSet() TranslationSet {
|
||||||
LcMoveUpCommit: "move commit up one",
|
LcMoveUpCommit: "move commit up one",
|
||||||
LcEditCommit: "edit commit",
|
LcEditCommit: "edit commit",
|
||||||
LcAmendToCommit: "amend commit with staged changes",
|
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",
|
LcRenameCommitEditor: "reword commit with editor",
|
||||||
Error: "Error",
|
Error: "Error",
|
||||||
LcSelectHunk: "select hunk",
|
LcSelectHunk: "select hunk",
|
||||||
|
@ -1125,6 +1130,7 @@ func EnglishTranslationSet() TranslationSet {
|
||||||
DropCommit: "Drop commit",
|
DropCommit: "Drop commit",
|
||||||
EditCommit: "Edit commit",
|
EditCommit: "Edit commit",
|
||||||
AmendCommit: "Amend commit",
|
AmendCommit: "Amend commit",
|
||||||
|
ResetCommitAuthor: "Reset commit author",
|
||||||
RevertCommit: "Revert commit",
|
RevertCommit: "Revert commit",
|
||||||
CreateFixupCommit: "Create fixup commit",
|
CreateFixupCommit: "Create fixup commit",
|
||||||
SquashAllAboveFixupCommits: "Squash all above fixup commits",
|
SquashAllAboveFixupCommits: "Squash all above fixup commits",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue