1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

Store commit.Action as an enum instead of a string

The main reason for doing this (besides the reasons given for Status in the
previous commit) is that it allows us to easily convert from TodoCommand to
Action and back. This will be needed later in the branch. Fortunately,
TodoCommand is one-based, so this allows us to add an ActionNone constant with
the value 0.
This commit is contained in:
Stefan Haller
2023-04-03 12:42:29 +02:00
parent 188773511e
commit c53c5e47ef
7 changed files with 57 additions and 45 deletions

View File

@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/go-errors/errors"
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/app/daemon"
@ -202,7 +203,7 @@ func (self *RebaseCommands) AmendTo(commit *models.Commit) error {
}
// EditRebaseTodo sets the action at a given index in the git-rebase-todo file
func (self *RebaseCommands) EditRebaseTodo(index int, action string) error {
func (self *RebaseCommands) EditRebaseTodo(index int, action todo.TodoCommand) error {
fileName := filepath.Join(self.dotGitDir, "rebase-merge/git-rebase-todo")
bytes, err := os.ReadFile(fileName)
if err != nil {
@ -216,7 +217,7 @@ func (self *RebaseCommands) EditRebaseTodo(index int, action string) error {
// it at the bottom, so we need to subtract our index from the commit count
contentIndex := commitCount - 1 - index
splitLine := strings.Split(content[contentIndex], " ")
content[contentIndex] = action + " " + strings.Join(splitLine[1:], " ")
content[contentIndex] = action.String() + " " + strings.Join(splitLine[1:], " ")
result := strings.Join(content, "\n")
return os.WriteFile(fileName, []byte(result), 0o644)