mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Allow deleting a merge commit
For non-merge commits we change "pick" to "drop" when we delete them. We do this so that we can use the same code for dropping a commit no matter whether we are in an interactive rebase or not. (If we aren't, we could just as well delete the pick line from the todo list instead of setting it to "drop", but if we are, it is better to keep the line around so that the user can change it back to "pick" if they change their mind.) However, merge commits can't be changed to "drop", so we have to delete them from the todo file. We add a new daemon instruction that does this. We still don't allow deleting a merge commit from within an interactive rebase. The reason is that we don't show the "label" and "reset" todos in lazygit, so deleting a merge commit would leave the commits from the branch that is being merged in the list as "pick" commits, with no indication that they are going to be dropped because they are on a different branch, and the merge commit that would have brought them in is gone. This could be very confusing.
This commit is contained in:
@ -290,3 +290,29 @@ func RemoveUpdateRefsForCopiedBranch(fileName string, commentChar byte) error {
|
||||
func isRenderedTodo(t todo.Todo) bool {
|
||||
return t.Commit != "" || t.Command == todo.UpdateRef
|
||||
}
|
||||
|
||||
func DropMergeCommit(fileName string, hash string, commentChar byte) error {
|
||||
todos, err := ReadRebaseTodoFile(fileName, commentChar)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newTodos, err := dropMergeCommit(todos, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return WriteRebaseTodoFile(fileName, newTodos, commentChar)
|
||||
}
|
||||
|
||||
func dropMergeCommit(todos []todo.Todo, hash string) ([]todo.Todo, error) {
|
||||
isMerge := func(t todo.Todo) bool {
|
||||
return t.Command == todo.Merge && t.Flag == "-C" && equalHash(t.Commit, hash)
|
||||
}
|
||||
if lo.CountBy(todos, isMerge) != 1 {
|
||||
return nil, fmt.Errorf("Expected exactly one merge commit with hash %s", hash)
|
||||
}
|
||||
|
||||
_, idx, _ := lo.FindIndexOf(todos, isMerge)
|
||||
return slices.Delete(todos, idx, idx+1), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user