From 76311082a3cb058ded2b057ac968977fba6bad1b Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sun, 6 Sep 2026 19:17:21 +0200 Subject: [PATCH 1/3] Pass only log to daemon.Handle, not the whole common The log is the only thing it needs. --- pkg/app/daemon/daemon.go | 43 ++++++++++++++++++++-------------------- pkg/app/daemon/rebase.go | 10 +++++----- pkg/app/entry_point.go | 2 +- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pkg/app/daemon/daemon.go b/pkg/app/daemon/daemon.go index 0b33bc12b..8cb79eda0 100644 --- a/pkg/app/daemon/daemon.go +++ b/pkg/app/daemon/daemon.go @@ -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) }) } diff --git a/pkg/app/daemon/rebase.go b/pkg/app/daemon/rebase.go index fdb58f23c..2a140b553 100644 --- a/pkg/app/daemon/rebase.go +++ b/pkg/app/daemon/rebase.go @@ -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 diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index a3225e311..31963d371 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -160,7 +160,7 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes } if daemon.InDaemonMode() { - daemon.Handle(common) + daemon.Handle(common.Log) return } From 37893d2b8ec761c7c246d819da573f0b1b01df63 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 7 Sep 2026 07:26:50 +0200 Subject: [PATCH 2/3] Construct logger separately and pass it into NewCommon This is a preparation for passing only the logger to daemon.Handle instead of the whole common. --- pkg/app/app.go | 7 +++---- pkg/app/entry_point.go | 6 +++++- pkg/cheatsheet/generate.go | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 15a3f327a..11f50c8b5 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -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) diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index 31963d371..fcffeb64b 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -93,6 +93,10 @@ 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 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,7 +158,7 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes appConfig.SaveGlobalUserConfig() } - common, err := NewCommon(appConfig) + common, err := NewCommon(appConfig, logger) if err != nil { log.Fatal(err) } diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 5c5a94530..ab4f764f8 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -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) } From 2f1301bd7d000bc5a43ac52051ea9e3d53ed1133 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 7 Sep 2026 07:27:59 +0200 Subject: [PATCH 3/3] Handle daemon mode before creating the app config Daemon mode doesn't have any reason to read the user config or try to migrate it if it's old. --- pkg/app/entry_point.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index fcffeb64b..ca445785b 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -97,6 +97,11 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes // 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) @@ -163,11 +168,6 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes log.Fatal(err) } - if daemon.InDaemonMode() { - daemon.Handle(common.Log) - return - } - if cliArgs.Profile { go func() { if err := http.ListenAndServe("localhost:6060", nil); err != nil {