mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
e33fe37a99
We've been sometimes using lo and sometimes using my slices package, and we need to pick one for consistency. Lo is more extensive and better maintained so we're going with that. My slices package was a superset of go's own slices package so in some places I've just used the official one (the methods were just wrappers anyway). I've also moved the remaining methods into the utils package.
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package daemon
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/fsmiamoto/git-todo-parser/todo"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/common"
|
|
"github.com/jesseduffield/lazygit/pkg/env"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
type TodoLine struct {
|
|
Action string
|
|
Commit *models.Commit
|
|
}
|
|
|
|
func (self *TodoLine) ToString() string {
|
|
if self.Action == "break" {
|
|
return self.Action + "\n"
|
|
} else {
|
|
return self.Action + " " + self.Commit.Sha + " " + self.Commit.Name + "\n"
|
|
}
|
|
}
|
|
|
|
func TodoLinesToString(todoLines []TodoLine) string {
|
|
lines := lo.Map(todoLines, func(todoLine TodoLine, _ int) string {
|
|
return todoLine.ToString()
|
|
})
|
|
|
|
return strings.Join(lo.Reverse(lines), "")
|
|
}
|
|
|
|
type ChangeTodoAction struct {
|
|
Sha string
|
|
NewAction todo.TodoCommand
|
|
}
|
|
|
|
func handleInteractiveRebase(common *common.Common, f func(path string) error) error {
|
|
common.Log.Info("Lazygit invoked as interactive rebase demon")
|
|
common.Log.Info("args: ", os.Args)
|
|
path := os.Args[1]
|
|
|
|
if strings.HasSuffix(path, "git-rebase-todo") {
|
|
return f(path)
|
|
} else if strings.HasSuffix(path, filepath.Join(gitDir(), "COMMIT_EDITMSG")) { // TODO: test
|
|
// if we are rebasing and squashing, we'll see a COMMIT_EDITMSG
|
|
// but in this case we don't need to edit it, so we'll just return
|
|
} else {
|
|
common.Log.Info("Lazygit demon did not match on any use cases")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func gitDir() string {
|
|
dir := env.GetGitDirEnv()
|
|
if dir == "" {
|
|
return ".git"
|
|
}
|
|
return dir
|
|
}
|