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

fix: use todo parser to properly read rebase todo file

This commit is contained in:
Francisco Miamoto
2022-05-22 13:42:56 -03:00
parent 0b08a0b298
commit d8dfed79b3

View File

@ -1,6 +1,7 @@
package loaders package loaders
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -9,6 +10,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/fsmiamoto/git-todo-parser/todo"
"github.com/jesseduffield/generics/slices" "github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
@ -307,21 +309,23 @@ func (self *CommitLoader) getInteractiveRebasingCommits() ([]*models.Commit, err
} }
commits := []*models.Commit{} commits := []*models.Commit{}
lines := strings.Split(string(bytesContent), "\n")
for _, line := range lines { todos, err := todo.Parse(bytes.NewBuffer(bytesContent))
if line == "" || line == "noop" { if err != nil {
return commits, nil self.Log.Error(fmt.Sprintf("error occurred while parsing git-rebase-todo file: %s", err.Error()))
return nil, nil
} }
if strings.HasPrefix(line, "#") {
for _, t := range todos {
if t.Commit == "" {
// Command does not have a commit associated, skip
continue continue
} }
splitLine := strings.Split(line, " ")
commits = slices.Prepend(commits, &models.Commit{ commits = slices.Prepend(commits, &models.Commit{
Sha: splitLine[1], Sha: t.Commit,
Name: strings.Join(splitLine[2:], " "), Name: t.Msg,
Status: "rebasing", Status: "rebasing",
Action: splitLine[0], Action: t.Command.String(),
}) })
} }