1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-07 22:02:56 +03:00

Simplify finding rebase todos

One of the comments we are deleting here said:

  // Comparing just the hash is not enough; we need to compare both the
  // action and the hash, as the hash could appear multiple times (e.g. in a
  // pick and later in a merge).

I don't remember what I was thinking when I wrote this code, but it's nonsense
of course. Maybe I was thinking that the hash that appears in a "merge" todo
would be the hash of the commit that is being merged in (which would then
actually appear in an earlier pick), but it isn't, it's the hash of the merge
commit itself (so that the rebase can reuse its commit message). Which means
that hashes are unique, no need to compare the action.
This commit is contained in:
Stefan Haller
2024-11-30 19:53:42 +01:00
parent 2823a7cff0
commit 64eb3d560b
4 changed files with 26 additions and 42 deletions

View File

@@ -26,7 +26,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Hash: "5678", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "5678"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "5678"},
@@ -41,7 +41,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Hash: "abcd", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "abcd"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -56,7 +56,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
},
todoToMoveDown: Todo{Ref: "refs/heads/some_branch", Action: todo.UpdateRef},
todoToMoveDown: Todo{Ref: "refs/heads/some_branch"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -73,7 +73,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "def0"},
},
todoToMoveDown: Todo{Hash: "5678", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "5678"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -92,7 +92,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Hash: "def0", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "def0"},
expectedErr: "Todo def0 not found in git-rebase-todo",
expectedTodos: []todo.Todo{},
},
@@ -103,7 +103,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveDown: Todo{Hash: "1234", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "1234"},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@@ -115,7 +115,7 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
{Command: todo.Pick, Commit: "1234"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveDown: Todo{Hash: "1234", Action: todo.Pick},
todoToMoveDown: Todo{Hash: "1234"},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@@ -152,7 +152,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Hash: "5678", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "5678"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -167,7 +167,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Hash: "1234", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "1234"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "5678"},
@@ -182,7 +182,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.UpdateRef, Ref: "refs/heads/some_branch"},
{Command: todo.Pick, Commit: "5678"},
},
todoToMoveUp: Todo{Ref: "refs/heads/some_branch", Action: todo.UpdateRef},
todoToMoveUp: Todo{Ref: "refs/heads/some_branch"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -199,7 +199,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "def0"},
},
todoToMoveUp: Todo{Hash: "abcd", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "abcd"},
expectedErr: "",
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -218,7 +218,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Hash: "def0", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "def0"},
expectedErr: "Todo def0 not found in git-rebase-todo",
expectedTodos: []todo.Todo{},
},
@@ -229,7 +229,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
{Command: todo.Pick, Commit: "abcd"},
},
todoToMoveUp: Todo{Hash: "abcd", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "abcd"},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@@ -241,7 +241,7 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
{Command: todo.Label, Label: "myLabel"},
{Command: todo.Reset, Label: "otherlabel"},
},
todoToMoveUp: Todo{Hash: "5678", Action: todo.Pick},
todoToMoveUp: Todo{Hash: "5678"},
expectedErr: "Destination position for moving todo is out of range",
expectedTodos: []todo.Todo{},
},
@@ -417,8 +417,8 @@ func TestRebaseCommands_deleteTodos(t *testing.T) {
{Command: todo.Pick, Commit: "abcd"},
},
todosToDelete: []Todo{
{Ref: "refs/heads/some_branch", Action: todo.UpdateRef},
{Hash: "abcd", Action: todo.Pick},
{Ref: "refs/heads/some_branch"},
{Hash: "abcd"},
},
expectedTodos: []todo.Todo{
{Command: todo.Pick, Commit: "1234"},
@@ -433,7 +433,7 @@ func TestRebaseCommands_deleteTodos(t *testing.T) {
{Command: todo.Pick, Commit: "5678"},
},
todosToDelete: []Todo{
{Hash: "abcd", Action: todo.Pick},
{Hash: "abcd"},
},
expectedTodos: []todo.Todo{},
expectedErr: errors.New("Todo abcd not found in git-rebase-todo"),