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