From 17bb3970c1a270b785c9854df329cb5d797b1857 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 29 Nov 2024 16:16:44 +0100 Subject: [PATCH] Filter out merge commits when generating todo changes in InteractiveRebase We will need this because under some conditions we are going to use this function to edit a range of commits, and we can't set merge commits to "edit". This corresponds to the code in startInteractiveRebaseWithEdit which has similar logic. It is a bit unfortunate that we will have these two different ways of setting todos to edit: startInteractiveRebaseWithEdit does it after stopping in the rebase, in the Then function of its refresh, but InteractiveRebase does it in the daemon with a ChangeTodoActionsInstruction. It still makes sense though, given how InteractiveRebase works. This not only affects "edit", but also "drop", "fixup", and "squash". Previously, when trying to use these for a range selection that includes a merge commit, they would fail with the cryptic error message "Some todos not found in git-rebase-todo"; now they simply exclude the merge commit. I'm not sure if one is better or worse than the other, and we should probably simply disable the commands when a merge commit is selected, but that's out of scope in this PR. --- pkg/commands/git_commands/rebase.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index a1362d725..3d1d36635 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -145,11 +145,11 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, startIdx baseHashOrRoot := getBaseHashOrRoot(commits, baseIndex) - changes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) daemon.ChangeTodoAction { + changes := lo.FilterMap(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) (daemon.ChangeTodoAction, bool) { return daemon.ChangeTodoAction{ Hash: commit.Hash, NewAction: action, - } + }, !commit.IsMerge() }) self.os.LogCommand(logTodoChanges(changes), false)