This commit is contained in:
Stefan Haller 2026-09-09 09:35:54 +02:00 committed by GitHub
commit 9030510900
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 38 deletions

View file

@ -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()
appState := config.GetAppState()
log := newLogger(config)
// Initialize with English for the time being; the real translation set for
// the configured language will be read after reading the user config
tr := i18n.EnglishTranslationSet()
@ -80,8 +79,8 @@ func NewCommon(config config.AppConfigurer) (*common.Common, error) {
return cmn, nil
}
func newLogger(cfg config.AppConfigurer) *logrus.Entry {
if cfg.GetDebug() {
func NewLogger(debug bool) *logrus.Entry {
if debug {
logPath, err := config.LogPath()
if err != nil {
log.Fatal(err)

View file

@ -3,14 +3,13 @@ package daemon
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strconv"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
"github.com/sirupsen/logrus"
)
// Sometimes lazygit will be invoked in daemon mode from a parent lazygit process.
@ -66,14 +65,14 @@ func getInstruction() Instruction {
return mapping[getDaemonKind()](jsonData)
}
func Handle(common *common.Common) {
func Handle(log *logrus.Entry) {
if !InDaemonMode() {
return
}
instruction := getInstruction()
if err := instruction.run(common); err != nil {
if err := instruction.run(log); err != nil {
log.Fatal(err)
}
}
@ -107,7 +106,7 @@ type Instruction interface {
SerializedInstructions() string
// runs the instruction
run(common *common.Common) error
run(log *logrus.Entry) error
}
func serializeInstruction[T any](instruction T) string {
@ -147,7 +146,7 @@ func (self *ExitImmediatelyInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *ExitImmediatelyInstruction) run(common *common.Common) error {
func (self *ExitImmediatelyInstruction) run(log *logrus.Entry) error {
return nil
}
@ -165,8 +164,8 @@ func (self *RemoveUpdateRefsForCopiedBranchInstruction) SerializedInstructions()
return serializeInstruction(self)
}
func (self *RemoveUpdateRefsForCopiedBranchInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
func (self *RemoveUpdateRefsForCopiedBranchInstruction) run(log *logrus.Entry) error {
return handleInteractiveRebase(log, func(path string) error {
return nil
})
}
@ -193,8 +192,8 @@ func (self *ChangeTodoActionsInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *ChangeTodoActionsInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
func (self *ChangeTodoActionsInstruction) run(log *logrus.Entry) error {
return handleInteractiveRebase(log, func(path string) error {
changes := lo.Map(self.Changes, func(c ChangeTodoAction, _ int) utils.TodoChange {
return utils.TodoChange{
Hash: c.Hash,
@ -225,8 +224,8 @@ func (self *DropMergeCommitInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *DropMergeCommitInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
func (self *DropMergeCommitInstruction) run(log *logrus.Entry) error {
return handleInteractiveRebase(log, func(path string) error {
return utils.DropMergeCommit(path, self.Hash, getCommentChar())
})
}
@ -256,8 +255,8 @@ func (self *MoveFixupCommitDownInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *MoveFixupCommitDownInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
func (self *MoveFixupCommitDownInstruction) run(log *logrus.Entry) error {
return handleInteractiveRebase(log, func(path string) error {
return utils.MoveFixupCommitDown(path, self.OriginalHash, self.FixupHash, self.ChangeToFixup, getCommentChar())
})
}
@ -282,14 +281,14 @@ func (self *MoveTodosUpInstruction) SerializedInstructions() string {
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 {
return utils.Todo{
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())
})
}
@ -314,14 +313,14 @@ func (self *MoveTodosDownInstruction) SerializedInstructions() string {
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 {
return utils.Todo{
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())
})
}
@ -340,8 +339,8 @@ func (self *InsertBreakInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *InsertBreakInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
func (self *InsertBreakInstruction) run(log *logrus.Entry) error {
return handleInteractiveRebase(log, func(path string) error {
return utils.PrependStrToTodoFile(path, []byte("break\n"))
})
}
@ -364,8 +363,8 @@ func (self *WriteRebaseTodoInstruction) SerializedInstructions() string {
return serializeInstruction(self)
}
func (self *WriteRebaseTodoInstruction) run(common *common.Common) error {
return handleInteractiveRebase(common, func(path string) error {
func (self *WriteRebaseTodoInstruction) run(log *logrus.Entry) error {
return handleInteractiveRebase(log, func(path string) error {
return os.WriteFile(path, self.TodosFileContent, 0o644)
})
}

View file

@ -5,9 +5,9 @@ import (
"path/filepath"
"strings"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/env"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
"github.com/stefanhaller/git-todo-parser/todo"
)
@ -17,9 +17,9 @@ type ChangeTodoAction struct {
Flag string
}
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)
func handleInteractiveRebase(log *logrus.Entry, f func(path string) error) error {
log.Info("Lazygit invoked as interactive rebase demon")
log.Info("args: ", os.Args)
path := os.Args[1]
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
// 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")
log.Info("Lazygit demon did not match on any use cases")
}
return nil

View file

@ -93,6 +93,15 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
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 {
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)
@ -154,16 +163,11 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
appConfig.SaveGlobalUserConfig()
}
common, err := NewCommon(appConfig)
common, err := NewCommon(appConfig, logger)
if err != nil {
log.Fatal(err)
}
if daemon.InDaemonMode() {
daemon.Handle(common)
return
}
if cliArgs.Profile {
go func() {
if err := http.ListenAndServe("localhost:6060", nil); err != nil {

View file

@ -58,10 +58,11 @@ func generateAtDir(cheatsheetDir string) {
log.Fatal(err)
}
mConfig := config.NewDummyAppConfig()
logger := app.NewLogger(mConfig.GetDebug())
for lang := range translationSetsByLang {
mConfig.GetUserConfig().Gui.Language = lang
common, err := app.NewCommon(mConfig)
common, err := app.NewCommon(mConfig, logger)
if err != nil {
log.Fatal(err)
}