1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/gpg.go

64 lines
1.9 KiB
Go
Raw Normal View History

2021-04-10 03:40:42 +02:00
package gui
import (
"fmt"
2021-12-07 12:59:36 +02:00
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
2021-04-10 03:40:42 +02:00
// 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.
2021-12-07 12:59:36 +02:00
// TODO: work out if we actually need to use a shell command here
func (gui *Gui) withGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
2021-04-10 03:40:42 +02:00
useSubprocess := gui.GitCommand.UsingGpg()
if useSubprocess {
2021-12-07 12:59:36 +02:00
success, err := gui.runSubprocessWithSuspense(gui.OSCommand.NewShellCmdObjFromString(cmdObj.ToString()))
2021-04-10 03:40:42 +02:00
if success && onSuccess != nil {
if err := onSuccess(); err != nil {
return err
}
}
if err := gui.refreshSidePanels(refreshOptions{mode: ASYNC}); err != nil {
return err
}
return err
2021-04-10 03:40:42 +02:00
} else {
2021-12-07 12:59:36 +02:00
return gui.RunAndStream(cmdObj, waitingStatus, onSuccess)
}
}
2021-12-07 12:59:36 +02:00
func (gui *Gui) RunAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error {
return gui.WithWaitingStatus(waitingStatus, func() error {
2021-12-07 12:59:36 +02:00
cmdObj := gui.OSCommand.NewShellCmdObjFromString(cmdObj.ToString())
cmdObj.AddEnvVars("TERM=dumb")
cmdWriter := gui.getCmdWriter()
2021-12-07 12:59:36 +02:00
cmd := cmdObj.GetCmd()
cmd.Stdout = cmdWriter
cmd.Stderr = cmdWriter
if err := cmd.Run(); err != nil {
if _, err := cmd.Stdout.Write([]byte(fmt.Sprintf("%s\n", style.FgRed.Sprint(err.Error())))); err != nil {
gui.Log.Error(err)
2021-04-10 03:40:42 +02:00
}
_ = gui.refreshSidePanels(refreshOptions{mode: ASYNC})
return gui.surfaceError(
fmt.Errorf(
2021-12-29 02:50:20 +02:00
gui.Tr.GitCommandFailed, gui.UserConfig.Keybinding.Universal.ExtrasMenu,
),
)
}
2021-04-10 03:40:42 +02:00
if onSuccess != nil {
if err := onSuccess(); err != nil {
return err
}
}
2021-04-10 03:40:42 +02:00
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
})
2021-04-10 03:40:42 +02:00
}