mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Merge 2f1301bd7d into d0ede21e9c
This commit is contained in:
commit
9030510900
|
|
@ -61,10 +61,9 @@ func Run(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommon(config config.AppConfigurer) (*common.Common, error) {
|
func NewCommon(config config.AppConfigurer, log *logrus.Entry) (*common.Common, error) {
|
||||||
userConfig := config.GetUserConfig()
|
userConfig := config.GetUserConfig()
|
||||||
appState := config.GetAppState()
|
appState := config.GetAppState()
|
||||||
log := newLogger(config)
|
|
||||||
// Initialize with English for the time being; the real translation set for
|
// Initialize with English for the time being; the real translation set for
|
||||||
// the configured language will be read after reading the user config
|
// the configured language will be read after reading the user config
|
||||||
tr := i18n.EnglishTranslationSet()
|
tr := i18n.EnglishTranslationSet()
|
||||||
|
|
@ -80,8 +79,8 @@ func NewCommon(config config.AppConfigurer) (*common.Common, error) {
|
||||||
return cmn, nil
|
return cmn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLogger(cfg config.AppConfigurer) *logrus.Entry {
|
func NewLogger(debug bool) *logrus.Entry {
|
||||||
if cfg.GetDebug() {
|
if debug {
|
||||||
logPath, err := config.LogPath()
|
logPath, err := config.LogPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,13 @@ package daemon
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sometimes lazygit will be invoked in daemon mode from a parent lazygit process.
|
// Sometimes lazygit will be invoked in daemon mode from a parent lazygit process.
|
||||||
|
|
@ -66,14 +65,14 @@ func getInstruction() Instruction {
|
||||||
return mapping[getDaemonKind()](jsonData)
|
return mapping[getDaemonKind()](jsonData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Handle(common *common.Common) {
|
func Handle(log *logrus.Entry) {
|
||||||
if !InDaemonMode() {
|
if !InDaemonMode() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
instruction := getInstruction()
|
instruction := getInstruction()
|
||||||
|
|
||||||
if err := instruction.run(common); err != nil {
|
if err := instruction.run(log); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -107,7 +106,7 @@ type Instruction interface {
|
||||||
SerializedInstructions() string
|
SerializedInstructions() string
|
||||||
|
|
||||||
// runs the instruction
|
// runs the instruction
|
||||||
run(common *common.Common) error
|
run(log *logrus.Entry) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func serializeInstruction[T any](instruction T) string {
|
func serializeInstruction[T any](instruction T) string {
|
||||||
|
|
@ -147,7 +146,7 @@ func (self *ExitImmediatelyInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ExitImmediatelyInstruction) run(common *common.Common) error {
|
func (self *ExitImmediatelyInstruction) run(log *logrus.Entry) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -165,8 +164,8 @@ func (self *RemoveUpdateRefsForCopiedBranchInstruction) SerializedInstructions()
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RemoveUpdateRefsForCopiedBranchInstruction) run(common *common.Common) error {
|
func (self *RemoveUpdateRefsForCopiedBranchInstruction) run(log *logrus.Entry) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -193,8 +192,8 @@ func (self *ChangeTodoActionsInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
|
func (self *ChangeTodoActionsInstruction) run(log *logrus.Entry) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
changes := lo.Map(self.Changes, func(c ChangeTodoAction, _ int) utils.TodoChange {
|
changes := lo.Map(self.Changes, func(c ChangeTodoAction, _ int) utils.TodoChange {
|
||||||
return utils.TodoChange{
|
return utils.TodoChange{
|
||||||
Hash: c.Hash,
|
Hash: c.Hash,
|
||||||
|
|
@ -225,8 +224,8 @@ func (self *DropMergeCommitInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *DropMergeCommitInstruction) run(common *common.Common) error {
|
func (self *DropMergeCommitInstruction) run(log *logrus.Entry) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return utils.DropMergeCommit(path, self.Hash, getCommentChar())
|
return utils.DropMergeCommit(path, self.Hash, getCommentChar())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -256,8 +255,8 @@ func (self *MoveFixupCommitDownInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error {
|
func (self *MoveFixupCommitDownInstruction) run(log *logrus.Entry) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, self.ChangeToFixup, getCommentChar())
|
return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, self.ChangeToFixup, getCommentChar())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -282,14 +281,14 @@ func (self *MoveTodosUpInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MoveTodosUpInstruction) run(common *common.Common) error {
|
func (self *MoveTodosUpInstruction) run(log *logrus.Entry) error {
|
||||||
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
|
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
|
||||||
return utils.Todo{
|
return utils.Todo{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return utils.MoveTodos(path, todosToMove, false, -self.Distance, getCommentChar())
|
return utils.MoveTodos(path, todosToMove, false, -self.Distance, getCommentChar())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -314,14 +313,14 @@ func (self *MoveTodosDownInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MoveTodosDownInstruction) run(common *common.Common) error {
|
func (self *MoveTodosDownInstruction) run(log *logrus.Entry) error {
|
||||||
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
|
todosToMove := lo.Map(self.Hashes, func(hash string, _ int) utils.Todo {
|
||||||
return utils.Todo{
|
return utils.Todo{
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return utils.MoveTodos(path, todosToMove, false, self.Distance, getCommentChar())
|
return utils.MoveTodos(path, todosToMove, false, self.Distance, getCommentChar())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -340,8 +339,8 @@ func (self *InsertBreakInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *InsertBreakInstruction) run(common *common.Common) error {
|
func (self *InsertBreakInstruction) run(log *logrus.Entry) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return utils.PrependStrToTodoFile(path, []byte("break\n"))
|
return utils.PrependStrToTodoFile(path, []byte("break\n"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -364,8 +363,8 @@ func (self *WriteRebaseTodoInstruction) SerializedInstructions() string {
|
||||||
return serializeInstruction(self)
|
return serializeInstruction(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *WriteRebaseTodoInstruction) run(common *common.Common) error {
|
func (self *WriteRebaseTodoInstruction) run(log *logrus.Entry) error {
|
||||||
return handleInteractiveRebase(common, func(path string) error {
|
return handleInteractiveRebase(log, func(path string) error {
|
||||||
return os.WriteFile(path, self.TodosFileContent, 0o644)
|
return os.WriteFile(path, self.TodosFileContent, 0o644)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
|
||||||
"github.com/jesseduffield/lazygit/pkg/env"
|
"github.com/jesseduffield/lazygit/pkg/env"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stefanhaller/git-todo-parser/todo"
|
"github.com/stefanhaller/git-todo-parser/todo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -17,9 +17,9 @@ type ChangeTodoAction struct {
|
||||||
Flag string
|
Flag string
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleInteractiveRebase(common *common.Common, f func(path string) error) error {
|
func handleInteractiveRebase(log *logrus.Entry, f func(path string) error) error {
|
||||||
common.Log.Info("Lazygit invoked as interactive rebase demon")
|
log.Info("Lazygit invoked as interactive rebase demon")
|
||||||
common.Log.Info("args: ", os.Args)
|
log.Info("args: ", os.Args)
|
||||||
path := os.Args[1]
|
path := os.Args[1]
|
||||||
|
|
||||||
if strings.HasSuffix(path, "git-rebase-todo") {
|
if strings.HasSuffix(path, "git-rebase-todo") {
|
||||||
|
|
@ -32,7 +32,7 @@ func handleInteractiveRebase(common *common.Common, f func(path string) error) e
|
||||||
// if we are rebasing and squashing, we'll see a COMMIT_EDITMSG
|
// 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
|
// but in this case we don't need to edit it, so we'll just return
|
||||||
} else {
|
} else {
|
||||||
common.Log.Info("Lazygit demon did not match on any use cases")
|
log.Info("Lazygit demon did not match on any use cases")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,15 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
|
||||||
env.SetGitDirEnv(cliArgs.GitDir)
|
env.SetGitDirEnv(cliArgs.GitDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The log file lives in the config dir, so this must come after setting the
|
||||||
|
// CONFIG_DIR env var above.
|
||||||
|
logger := NewLogger(cliArgs.Debug)
|
||||||
|
|
||||||
|
if daemon.InDaemonMode() {
|
||||||
|
daemon.Handle(logger)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if cliArgs.PrintVersionInfo {
|
if cliArgs.PrintVersionInfo {
|
||||||
gitVersion := getGitVersionInfo()
|
gitVersion := getGitVersionInfo()
|
||||||
fmt.Printf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s, git version=%s\n", buildInfo.Commit, buildInfo.Date, buildInfo.BuildSource, buildInfo.Version, runtime.GOOS, runtime.GOARCH, gitVersion)
|
fmt.Printf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s, git version=%s\n", buildInfo.Commit, buildInfo.Date, buildInfo.BuildSource, buildInfo.Version, runtime.GOOS, runtime.GOARCH, gitVersion)
|
||||||
|
|
@ -154,16 +163,11 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
|
||||||
appConfig.SaveGlobalUserConfig()
|
appConfig.SaveGlobalUserConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
common, err := NewCommon(appConfig)
|
common, err := NewCommon(appConfig, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if daemon.InDaemonMode() {
|
|
||||||
daemon.Handle(common)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if cliArgs.Profile {
|
if cliArgs.Profile {
|
||||||
go func() {
|
go func() {
|
||||||
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
|
if err := http.ListenAndServe("localhost:6060", nil); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,11 @@ func generateAtDir(cheatsheetDir string) {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
mConfig := config.NewDummyAppConfig()
|
mConfig := config.NewDummyAppConfig()
|
||||||
|
logger := app.NewLogger(mConfig.GetDebug())
|
||||||
|
|
||||||
for lang := range translationSetsByLang {
|
for lang := range translationSetsByLang {
|
||||||
mConfig.GetUserConfig().Gui.Language = lang
|
mConfig.GetUserConfig().Gui.Language = lang
|
||||||
common, err := app.NewCommon(mConfig)
|
common, err := app.NewCommon(mConfig, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue