mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
Allow deleting update-ref todos
This commit is contained in:
parent
64a1a455d6
commit
0608fc6471
7 changed files with 215 additions and 1 deletions
|
@ -106,7 +106,7 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [
|
|||
Handler: self.withItemsRange(self.drop),
|
||||
GetDisabledReason: self.require(
|
||||
self.itemRangeSelected(
|
||||
self.midRebaseCommandEnabled,
|
||||
self.canDropCommits,
|
||||
),
|
||||
),
|
||||
Description: self.c.Tr.DropCommit,
|
||||
|
@ -439,6 +439,36 @@ func (self *LocalCommitsController) rewordEditor(commit *models.Commit) error {
|
|||
|
||||
func (self *LocalCommitsController) drop(selectedCommits []*models.Commit, startIdx int, endIdx int) error {
|
||||
if self.isRebasing() {
|
||||
groupedTodos := lo.GroupBy(selectedCommits, func(c *models.Commit) bool {
|
||||
return c.Action == todo.UpdateRef
|
||||
})
|
||||
updateRefTodos := groupedTodos[true]
|
||||
nonUpdateRefTodos := groupedTodos[false]
|
||||
|
||||
if len(updateRefTodos) > 0 {
|
||||
return self.c.Confirm(types.ConfirmOpts{
|
||||
Title: self.c.Tr.DropCommitTitle,
|
||||
Prompt: self.c.Tr.DropUpdateRefPrompt,
|
||||
HandleConfirm: func() error {
|
||||
selectedIdx, rangeStartIdx, rangeSelectMode := self.context().GetSelectionRangeAndMode()
|
||||
|
||||
if err := self.c.Git().Rebase.DeleteUpdateRefTodos(updateRefTodos); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if selectedIdx > rangeStartIdx {
|
||||
selectedIdx = utils.Max(selectedIdx-len(updateRefTodos), rangeStartIdx)
|
||||
} else {
|
||||
rangeStartIdx = utils.Max(rangeStartIdx-len(updateRefTodos), selectedIdx)
|
||||
}
|
||||
|
||||
self.context().SetSelectionRangeAndMode(selectedIdx, rangeStartIdx, rangeSelectMode)
|
||||
|
||||
return self.updateTodos(todo.Drop, nonUpdateRefTodos)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return self.updateTodos(todo.Drop, selectedCommits)
|
||||
}
|
||||
|
||||
|
@ -1213,6 +1243,28 @@ func (self *LocalCommitsController) midRebaseMoveCommandEnabled(selectedCommits
|
|||
return nil
|
||||
}
|
||||
|
||||
func (self *LocalCommitsController) canDropCommits(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason {
|
||||
if !self.isRebasing() {
|
||||
return nil
|
||||
}
|
||||
|
||||
nonUpdateRefTodos := lo.Filter(selectedCommits, func(c *models.Commit, _ int) bool {
|
||||
return c.Action != todo.UpdateRef
|
||||
})
|
||||
|
||||
for _, commit := range nonUpdateRefTodos {
|
||||
if !commit.IsTODO() {
|
||||
return &types.DisabledReason{Text: self.c.Tr.MustSelectTodoCommits}
|
||||
}
|
||||
|
||||
if !isChangeOfRebaseTodoAllowed(commit.Action) {
|
||||
return &types.DisabledReason{Text: self.c.Tr.ChangingThisActionIsNotAllowed}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// These actions represent standard things you might want to do with a commit,
|
||||
// as opposed to TODO actions like 'merge', 'update-ref', etc.
|
||||
var standardActions = []todo.TodoCommand{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue