1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-25 22:32:13 +02:00

Fix moving a commit across a branch boundary in a stack

See the previous commit for a detailed explanation.
This commit is contained in:
Stefan Haller
2024-12-02 11:35:35 +01:00
parent cf27974ea3
commit a9ef69b9c7
5 changed files with 60 additions and 29 deletions

View File

@@ -14,6 +14,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
testName string
todos []todo.Todo
todoToMoveDown Todo
isInRebase bool
expectedErr string
expectedTodos []todo.Todo
}
@@ -65,13 +66,14 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
},
},
{
testName: "move across update-ref todo",
testName: "move across update-ref todo in rebase",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveDown: Todo{Hash: "5678"},
isInRebase: true,
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -79,6 +81,22 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
},
},
{
testName: "move across update-ref todo outside of rebase",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveDown: Todo{Hash: "5678"},
isInRebase: false,
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "1234"},
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
},
},
{
testName: "move across exec todo",
todos: []todo.Todo{
@@ -87,6 +105,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveDown: Todo{Hash: "5678"},
isInRebase: true,
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -153,7 +172,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
rearrangedTodos, err := moveTodoDown(s.todos, s.todoToMoveDown)
rearrangedTodos, err := moveTodoDown(s.todos, s.todoToMoveDown, s.isInRebase)
if s.expectedErr == "" {
assert.NoError(t, err)
} else {
@@ -170,6 +189,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
testName string
todos []todo.Todo
todoToMoveUp Todo
isInRebase bool
expectedErr string
expectedTodos []todo.Todo
}
@@ -221,13 +241,14 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
},
},
{
testName: "move across update-ref todo",
testName: "move across update-ref todo in rebase",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveUp: Todo{Hash: "1234"},
isInRebase: true,
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
@@ -235,6 +256,22 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
},
},
{
testName: "move across update-ref todo outside of rebase",
todos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveUp: Todo{Hash: "1234"},
isInRebase: false,
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "1234"},
},
},
{
testName: "move across exec todo",
todos: []todo.Todo{
@@ -243,6 +280,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveUp: Todo{Hash: "1234"},
isInRebase: true,
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Exec, ExecCommand: "make test"},
@@ -309,7 +347,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
for _, s := range scenarios {
t.Run(s.testName, func(t *testing.T) {
rearrangedTodos, err := moveTodoUp(s.todos, s.todoToMoveUp)
rearrangedTodos, err := moveTodoUp(s.todos, s.todoToMoveUp, s.isInRebase)
if s.expectedErr == "" {
assert.NoError(t, err)
} else {