From 10d2f9f7156fd0343a2b78b358591cc0a49025ff Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 22 Jun 2026 09:22:18 +0200 Subject: [PATCH] Allow GpgHelper to refresh differently on success and failure Preparation for the next commit, which selects the newly created commit after a commit succeeds, while leaving the selection alone on failure. For now success and failure use the same refresh options, so behavior is unchanged. --- pkg/gui/controllers/helpers/gpg_helper.go | 37 +++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/pkg/gui/controllers/helpers/gpg_helper.go b/pkg/gui/controllers/helpers/gpg_helper.go index e8e46e403..46fbee703 100644 --- a/pkg/gui/controllers/helpers/gpg_helper.go +++ b/pkg/gui/controllers/helpers/gpg_helper.go @@ -19,16 +19,29 @@ func NewGpgHelper(c *HelperCommon) *GpgHelper { } } -// Currently there is a bug where if we switch to a subprocess from within -// WithWaitingStatus we get stuck there and can't return to lazygit. We could -// fix this bug, or just stop running subprocesses from within there, given that -// we don't need to see a loading status if we're in a subprocess. func (self *GpgHelper) WithGpgHandling( cmdObj *oscommands.CmdObj, configKey git_commands.GpgConfigKey, waitingStatus string, onSuccess func() error, refreshScope []types.RefreshableView, +) error { + refreshOptions := types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope} + return self.withGpgHandling( + cmdObj, configKey, waitingStatus, onSuccess, refreshOptions, refreshOptions) +} + +// Currently there is a bug where if we switch to a subprocess from within +// WithWaitingStatus we get stuck there and can't return to lazygit. We could +// fix this bug, or just stop running subprocesses from within there, given that +// we don't need to see a loading status if we're in a subprocess. +func (self *GpgHelper) withGpgHandling( + cmdObj *oscommands.CmdObj, + configKey git_commands.GpgConfigKey, + waitingStatus string, + onSuccess func() error, + failureRefreshOptions types.RefreshOptions, + successRefreshOptions types.RefreshOptions, ) error { useSubprocess := self.c.Git().Config.NeedsGpgSubprocess(configKey) if useSubprocess { @@ -38,23 +51,29 @@ func (self *GpgHelper) WithGpgHandling( return err } } - self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope}) + if success { + self.c.Refresh(successRefreshOptions) + } else { + self.c.Refresh(failureRefreshOptions) + } return err } - return self.runAndStream(cmdObj, waitingStatus, onSuccess, refreshScope) + return self.runAndStream( + cmdObj, waitingStatus, onSuccess, failureRefreshOptions, successRefreshOptions) } func (self *GpgHelper) runAndStream( cmdObj *oscommands.CmdObj, waitingStatus string, onSuccess func() error, - refreshScope []types.RefreshableView, + failureRefreshOptions types.RefreshOptions, + successRefreshOptions types.RefreshOptions, ) error { return self.c.WithWaitingStatus(waitingStatus, func(gocui.Task) error { if err := cmdObj.StreamOutput().Run(); err != nil { - self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope}) + self.c.Refresh(failureRefreshOptions) return fmt.Errorf( self.c.Tr.GitCommandFailed, self.c.UserConfig().Keybinding.Universal.ExtrasMenu, ) @@ -66,7 +85,7 @@ func (self *GpgHelper) runAndStream( } } - self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: refreshScope}) + self.c.Refresh(successRefreshOptions) return nil }) }