summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon <brandondong96@gmail.com>2024-04-21 12:52:02 -0700
committerBrandon <brandondong96@gmail.com>2024-04-22 08:48:59 -0700
commitef99e47d09f4c3d474c8a239c3cb029c06c241c3 (patch)
treea81e2abd9ef9574e0a6ea3b578ff9895346cbaf0
parent580818e935e19a67f7fe1bbb148224a95781879c (diff)
Fix amend to operation not working with non-HEAD merge commit
-rw-r--r--pkg/utils/rebase_todo.go2
-rw-r--r--pkg/utils/rebase_todo_test.go17
2 files changed, 17 insertions, 2 deletions
diff --git a/pkg/utils/rebase_todo.go b/pkg/utils/rebase_todo.go
index fca1944f1..216d56f26 100644
--- a/pkg/utils/rebase_todo.go
+++ b/pkg/utils/rebase_todo.go
@@ -235,7 +235,7 @@ func MoveFixupCommitDown(fileName string, originalHash string, fixupHash string,
func moveFixupCommitDown(todos []todo.Todo, originalHash string, fixupHash string) ([]todo.Todo, error) {
isOriginal := func(t todo.Todo) bool {
- return t.Command == todo.Pick && equalHash(t.Commit, originalHash)
+ return (t.Command == todo.Pick || t.Command == todo.Merge) && equalHash(t.Commit, originalHash)
}
isFixup := func(t todo.Todo) bool {
diff --git a/pkg/utils/rebase_todo_test.go b/pkg/utils/rebase_todo_test.go
index 9e7e6ca97..913b055cd 100644
--- a/pkg/utils/rebase_todo_test.go
+++ b/pkg/utils/rebase_todo_test.go
@@ -284,7 +284,6 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
expectedErr: nil,
},
{
- // TODO: is this something we actually want to support?
name: "fixup commit is separated from original commit",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},
@@ -301,6 +300,22 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
expectedErr: nil,
},
{
+ name: "fixup commit is separated from original merge commit",
+ todos: []todo.Todo{
+ {Command: todo.Merge, Commit: "original"},
+ {Command: todo.Pick, Commit: "other"},
+ {Command: todo.Pick, Commit: "fixup"},
+ },
+ originalHash: "original",
+ fixupHash: "fixup",
+ expectedTodos: []todo.Todo{
+ {Command: todo.Merge, Commit: "original"},
+ {Command: todo.Fixup, Commit: "fixup"},
+ {Command: todo.Pick, Commit: "other"},
+ },
+ expectedErr: nil,
+ },
+ {
name: "More original hashes than expected",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "original"},