Remove the moving of todos by a number of rows outside of a rebase

Moving commits outside of a rebase now names the commit that they go on
top of, so nothing moves them by a number of rows any more. Moving todos
by a number of rows is left only for the rebase todo, where update-ref
and exec todos are rows of their own.

MoveTodosDown and MoveTodosUp of RebaseCommands were unused already;
remove them too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-11-12 15:26:39 +01:00
1 parent 10f8000e59
commit af3cad16eb
4 files changed
+21 -172

No files matched your search

-68
View File
@@ -31,8 +31,6 @@ const (
DaemonKindExitImmediately
DaemonKindRemoveUpdateRefsForCopiedBranch
DaemonKindMoveTodosUp
DaemonKindMoveTodosDown
DaemonKindInsertBreak
DaemonKindChangeTodoActions
DaemonKindDropMergeCommit
@@ -57,8 +55,6 @@ func getInstruction() Instruction {
DaemonKindChangeTodoActions: deserializeInstruction[*ChangeTodoActionsInstruction],
DaemonKindDropMergeCommit: deserializeInstruction[*DropMergeCommitInstruction],
DaemonKindMoveFixupCommitDown: deserializeInstruction[*MoveFixupCommitDownInstruction],
DaemonKindMoveTodosUp: deserializeInstruction[*MoveTodosUpInstruction],
DaemonKindMoveTodosDown: deserializeInstruction[*MoveTodosDownInstruction],
DaemonKindInsertBreak: deserializeInstruction[*InsertBreakInstruction],
DaemonKindWriteRebaseTodo: deserializeInstruction[*WriteRebaseTodoInstruction],
DaemonKindMoveCommitTodos: deserializeInstruction[*MoveCommitTodosInstruction],
@@ -263,70 +259,6 @@ func (self *MoveFixupCommitDownInstruction) run(log *logrus.Entry) error {
})
}
type MoveTodosUpInstruction struct {
Hashes []string
Distance int
}
func NewMoveTodosUpInstruction(hashes []string, distance int) Instruction {
return &MoveTodosUpInstruction{
Hashes: hashes,
Distance: distance,
}
}
func (self *MoveTodosUpInstruction) Kind() DaemonKind {
return DaemonKindMoveTodosUp
}
func (self *MoveTodosUpInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *MoveTodosUpInstruction) run(log *logrus.Entry) error {
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
return utils.Todo{
Hash: hash,
}
})
return handleInteractiveRebase(log, func(path string) error {
return utils.MoveTodos(path, todosToMove, false, -self.Distance, getCommentChar())
})
}
type MoveTodosDownInstruction struct {
Hashes []string
Distance int
}
func NewMoveTodosDownInstruction(hashes []string, distance int) Instruction {
return &MoveTodosDownInstruction{
Hashes: hashes,
Distance: distance,
}
}
func (self *MoveTodosDownInstruction) Kind() DaemonKind {
return DaemonKindMoveTodosDown
}
func (self *MoveTodosDownInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *MoveTodosDownInstruction) run(log *logrus.Entry) error {
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
return utils.Todo{
Hash: hash,
}
})
return handleInteractiveRebase(log, func(path string) error {
return utils.MoveTodos(path, todosToMove, false, self.Distance, getCommentChar())
})
}
type MoveCommitTodosInstruction struct {
Hashes []string
Destination utils.TodoMoveDestination
+1 -38
View File
@@ -111,35 +111,6 @@ func (self *RebaseCommands) GenericAmend(commits []*models.Commit, start, end in
return nil
}
func (self *RebaseCommands) MoveCommitsDown(commits []*models.Commit, startIdx int, endIdx int) error {
return self.MoveCommits(commits, startIdx, endIdx, 1)
}
func (self *RebaseCommands) MoveCommitsUp(commits []*models.Commit, startIdx int, endIdx int) error {
return self.MoveCommits(commits, startIdx, endIdx, -1)
}
func (self *RebaseCommands) MoveCommits(commits []*models.Commit, startIdx int, endIdx int, offset int) error {
baseHashOrRoot := getBaseHashOrRoot(commits, endIdx+max(offset, 0)+1)
hashes := lo.Map(commits[startIdx:endIdx+1], func(commit *models.Commit, _ int) string {
return commit.Hash()
})
var instruction daemon.Instruction
if offset > 0 {
instruction = daemon.NewMoveTodosDownInstruction(hashes, offset)
} else {
instruction = daemon.NewMoveTodosUpInstruction(hashes, -offset)
}
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseHashOrRoot: baseHashOrRoot,
instruction: instruction,
overrideEditor: true,
}).Run()
}
// MoveCommitsTo moves the commits from startIdx to endIdx so that they sit
// directly on top of the commit at destinationIdx, which must be outside of
// that range; if destinationIdx is len(commits), they go below the last
@@ -421,21 +392,13 @@ func (self *RebaseCommands) DeleteUpdateRefTodos(commits []*models.Commit) error
return self.GitRebaseEditTodo(todosFileContent)
}
func (self *RebaseCommands) MoveTodosDown(commits []*models.Commit) error {
return self.MoveTodos(commits, 1)
}
func (self *RebaseCommands) MoveTodosUp(commits []*models.Commit) error {
return self.MoveTodos(commits, -1)
}
func (self *RebaseCommands) MoveTodos(commits []*models.Commit, offset int) error {
fileName := filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge/git-rebase-todo")
todosToMove := lo.Map(commits, func(commit *models.Commit, _ int) utils.Todo {
return todoFromCommit(commit)
})
return utils.MoveTodos(fileName, todosToMove, true, offset, self.config.GetCoreCommentChar())
return utils.MoveTodos(fileName, todosToMove, offset, self.config.GetCoreCommentChar())
}
// SquashAllAboveFixupCommits squashes all fixup! commits above the given one
+14 -22
View File
@@ -177,27 +177,19 @@ func deleteTodos(todos []todo.Todo, todosToDelete []Todo) ([]todo.Todo, error) {
return todos, nil
}
func MoveTodosDown(fileName string, todosToMove []Todo, isInRebase bool, commentChar byte) error {
return MoveTodos(fileName, todosToMove, isInRebase, 1, commentChar)
}
func MoveTodosUp(fileName string, todosToMove []Todo, isInRebase bool, commentChar byte) error {
return MoveTodos(fileName, todosToMove, isInRebase, -1, commentChar)
}
func MoveTodos(fileName string, todosToMove []Todo, isInRebase bool, offset int, commentChar byte) error {
func MoveTodos(fileName string, todosToMove []Todo, offset int, commentChar byte) error {
todos, err := ReadRebaseTodoFile(fileName, commentChar)
if err != nil {
return err
}
rearrangedTodos, err := moveTodos(todos, todosToMove, isInRebase, offset)
rearrangedTodos, err := moveTodos(todos, todosToMove, offset)
if err != nil {
return err
}
return WriteRebaseTodoFile(fileName, rearrangedTodos, commentChar)
}
func moveTodos(todos []todo.Todo, todosToMove []Todo, isInRebase bool, offset int) ([]todo.Todo, error) {
func moveTodos(todos []todo.Todo, todosToMove []Todo, offset int) ([]todo.Todo, error) {
moveOneRow := moveTodosUp
if offset > 0 {
moveOneRow = moveTodosDown
@@ -205,7 +197,7 @@ func moveTodos(todos []todo.Todo, todosToMove []Todo, isInRebase bool, offset in
for range max(offset, -offset) {
var err error
todos, err = moveOneRow(todos, slices.Clone(todosToMove), isInRebase)
todos, err = moveOneRow(todos, slices.Clone(todosToMove))
if err != nil {
return nil, err
}
@@ -214,17 +206,17 @@ func moveTodos(todos []todo.Todo, todosToMove []Todo, isInRebase bool, offset in
return todos, nil
}
func moveTodoDown(todos []todo.Todo, todoToMove Todo, isInRebase bool) ([]todo.Todo, error) {
rearrangedTodos, err := moveTodoUp(lo.Reverse(todos), todoToMove, isInRebase)
func moveTodoDown(todos []todo.Todo, todoToMove Todo) ([]todo.Todo, error) {
rearrangedTodos, err := moveTodoUp(lo.Reverse(todos), todoToMove)
return lo.Reverse(rearrangedTodos), err
}
func moveTodosDown(todos []todo.Todo, todosToMove []Todo, isInRebase bool) ([]todo.Todo, error) {
rearrangedTodos, err := moveTodosUp(lo.Reverse(todos), lo.Reverse(todosToMove), isInRebase)
func moveTodosDown(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) {
rearrangedTodos, err := moveTodosUp(lo.Reverse(todos), lo.Reverse(todosToMove))
return lo.Reverse(rearrangedTodos), err
}
func moveTodoUp(todos []todo.Todo, todoToMove Todo, isInRebase bool) ([]todo.Todo, error) {
func moveTodoUp(todos []todo.Todo, todoToMove Todo) ([]todo.Todo, error) {
sourceIdx, ok := findTodo(todos, todoToMove)
if !ok {
@@ -237,7 +229,7 @@ func moveTodoUp(todos []todo.Todo, todoToMove Todo, isInRebase bool) ([]todo.Tod
// the end of the slice)
// Find the next todo that we show in lazygit's commits view (skipping the rest)
_, skip, ok := lo.FindIndexOf(todos[sourceIdx+1:], func(t todo.Todo) bool { return isRenderedTodo(t, isInRebase) })
_, skip, ok := lo.FindIndexOf(todos[sourceIdx+1:], isRenderedTodo)
if !ok {
// We expect callers to guard against this
@@ -251,10 +243,10 @@ func moveTodoUp(todos []todo.Todo, todoToMove Todo, isInRebase bool) ([]todo.Tod
return rearrangedTodos, nil
}
func moveTodosUp(todos []todo.Todo, todosToMove []Todo, isInRebase bool) ([]todo.Todo, error) {
func moveTodosUp(todos []todo.Todo, todosToMove []Todo) ([]todo.Todo, error) {
for _, todoToMove := range todosToMove {
var newTodos []todo.Todo
newTodos, err := moveTodoUp(todos, todoToMove, isInRebase)
newTodos, err := moveTodoUp(todos, todoToMove)
if err != nil {
return nil, err
}
@@ -420,8 +412,8 @@ func RemoveUpdateRefsForCopiedBranch(fileName string, commentChar byte) error {
// We render a todo in the commits view if it's a commit or if it's an
// update-ref or exec. We don't render label, reset, or comment lines.
func isRenderedTodo(t todo.Todo, isInRebase bool) bool {
return t.Commit != "" || (isInRebase && (t.Command == todo.UpdateRef || t.Command == todo.Exec))
func isRenderedTodo(t todo.Todo) bool {
return t.Commit != "" || t.Command == todo.UpdateRef || t.Command == todo.Exec
}
func DropMergeCommit(fileName string, hash string, commentChar byte) error {
+6 -44
View File
@@ -22,7 +22,7 @@ func TestMoveTodos(t *testing.T) {
}
t.Run("moves a range up multiple rendered rows", func(t *testing.T) {
actual, err := moveTodos(slices.Clone(todos), []Todo{{Hash: "d"}, {Hash: "c"}}, false, -2)
actual, err := moveTodos(slices.Clone(todos), []Todo{{Hash: "d"}, {Hash: "c"}}, -2)
assert.NoError(t, err)
assert.Equal(t, []todo.Todo{
@@ -37,7 +37,7 @@ func TestMoveTodos(t *testing.T) {
})
t.Run("moves a range down multiple rendered rows", func(t *testing.T) {
actual, err := moveTodos(slices.Clone(todos), []Todo{{Hash: "e"}, {Hash: "d"}}, false, 2)
actual, err := moveTodos(slices.Clone(todos), []Todo{{Hash: "e"}, {Hash: "d"}}, 2)
assert.NoError(t, err)
assert.Equal(t, []todo.Todo{
@@ -235,7 +235,6 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
testName string
todos []todo.Todo
todoToMoveDown Todo
isInRebase bool
expectedErr string
expectedTodos []todo.Todo
}
@@ -287,14 +286,13 @@ func TestRebaseCommands_moveTodoDown(t *testing.T) {
},
},
{
testName: "move across update-ref todo in rebase",
testName: "move across update-ref todo",
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"},
@@ -302,22 +300,6 @@ 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{
@@ -326,7 +308,6 @@ 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"},
@@ -393,7 +374,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, s.isInRebase)
rearrangedTodos, err := moveTodoDown(s.todos, s.todoToMoveDown)
if s.expectedErr == "" {
assert.NoError(t, err)
} else {
@@ -410,7 +391,6 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
testName string
todos []todo.Todo
todoToMoveUp Todo
isInRebase bool
expectedErr string
expectedTodos []todo.Todo
}
@@ -462,14 +442,13 @@ func TestRebaseCommands_moveTodoUp(t *testing.T) {
},
},
{
testName: "move across update-ref todo in rebase",
testName: "move across update-ref todo",
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"},
@@ -477,22 +456,6 @@ 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{
@@ -501,7 +464,6 @@ 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"},
@@ -568,7 +530,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, s.isInRebase)
rearrangedTodos, err := moveTodoUp(s.todos, s.todoToMoveUp)
if s.expectedErr == "" {
assert.NoError(t, err)
} else {