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

support setting the author of a commit

update copy
This commit is contained in:
Jesse Duffield
2022-05-08 21:05:01 +10:00
parent 901ab3ac1b
commit 9591cc381a
31 changed files with 141 additions and 14 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/jesseduffield/minimal/gitignore"
"github.com/samber/lo"
"gopkg.in/ozeidan/fuzzy-patricia.v3/patricia"
)
@ -174,6 +175,14 @@ func (self *SuggestionsHelper) GetRefsSuggestionsFunc() func(string) []*types.Su
return FuzzySearchFunc(refNames)
}
func (self *SuggestionsHelper) GetAuthorsSuggestionsFunc() func(string) []*types.Suggestion {
authors := lo.Uniq(slices.Map(self.model.Commits, func(commit *models.Commit) string {
return fmt.Sprintf("%s <%s>", commit.AuthorName, commit.AuthorEmail)
}))
return FuzzySearchFunc(authors)
}
func FuzzySearchFunc(options []string) func(string) []*types.Suggestion {
return func(input string) []*types.Suggestion {
var matches []string

View File

@ -123,7 +123,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
},
{
Key: opts.GetKey(opts.Config.Commits.ResetCommitAuthor),
Handler: self.checkSelected(self.resetAuthor),
Handler: self.checkSelected(self.amendAttribute),
Description: self.c.Tr.LcResetCommitAuthor,
},
{
@ -423,17 +423,50 @@ 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)
}
func (self *LocalCommitsController) amendAttribute(commit *models.Commit) error {
return self.c.Menu(types.CreateMenuOptions{
Title: "Amend commit attribute",
Items: []*types.MenuItem{
{
Label: "reset author",
OnPress: self.resetAuthor,
Key: 'a',
Tooltip: "Reset the commit's author to the currently configured user. This will also renew the author timestamp",
},
{
Label: "set author",
OnPress: self.setAuthor,
Key: 'A',
Tooltip: "Set the author based on a prompt",
},
},
})
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
func (self *LocalCommitsController) resetAuthor() error {
return self.c.WithWaitingStatus(self.c.Tr.AmendingStatus, 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) setAuthor() error {
return self.c.Prompt(types.PromptOpts{
Title: self.c.Tr.SetAuthorPromptTitle,
FindSuggestionsFunc: self.helpers.Suggestions.GetAuthorsSuggestionsFunc(),
HandleConfirm: func(value string) error {
return self.c.WithWaitingStatus(self.c.Tr.AmendingStatus, func() error {
self.c.LogAction(self.c.Tr.Actions.SetCommitAuthor)
if err := self.git.Rebase.SetCommitAuthor(self.model.Commits, self.context().GetSelectedLineIdx(), value); err != nil {
return self.c.Error(err)
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
})
},
})
}