summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-09 11:32:27 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-09 21:30:19 +1000
commit14ecc15e71f648a95dab297ce9360d0badb6669a (patch)
tree8a60cc5a3e9836688e6e1943266541a76628b141 /pkg
parent9e79ee5fe36dc849479ce8f3b05e7cca56c7c216 (diff)
Use first class task objects instead of global counter
The global counter approach is easy to understand but it's brittle and depends on implicit behaviour that is not very discoverable. With a global counter, if any goroutine accidentally decrements the counter twice, we'll think lazygit is idle when it's actually busy. Likewise if a goroutine accidentally increments the counter twice we'll think lazygit is busy when it's actually idle. With the new approach we have a map of tasks where each task can either be busy or not. We create a new task and add it to the map when we spawn a worker goroutine (among other things) and we remove it once the task is done. The task can also be paused and continued for situations where we switch back and forth between running a program and asking for user input. In order for this to work with `git push` (and other commands that require credentials) we need to obtain the task from gocui when we create the worker goroutine, and then pass it along to the commands package to pause/continue the task as required. This is MUCH more discoverable than the old approach which just decremented and incremented the global counter from within the commands package, but it's at the cost of expanding some function signatures (arguably a good thing). Likewise, whenever you want to call WithWaitingStatus or WithLoaderPanel the callback will now have access to the task for pausing/ continuing. We only need to actually make use of this functionality in a couple of places so it's a high price to pay, but I don't know if I want to introduce a WithWaitingStatusTask and WithLoaderPanelTask function (open to suggestions).
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_commands/remote.go6
-rw-r--r--pkg/commands/git_commands/sync.go47
-rw-r--r--pkg/commands/git_commands/tag.go6
-rw-r--r--pkg/commands/oscommands/cmd_obj.go12
-rw-r--r--pkg/commands/oscommands/cmd_obj_runner.go12
-rw-r--r--pkg/commands/oscommands/gui_io.go9
-rw-r--r--pkg/gui/background.go6
-rw-r--r--pkg/gui/controllers/branches_controller.go6
-rw-r--r--pkg/gui/controllers/commits_files_controller.go4
-rw-r--r--pkg/gui/controllers/custom_patch_options_menu_action.go9
-rw-r--r--pkg/gui/controllers/files_controller.go9
-rw-r--r--pkg/gui/controllers/files_remove_controller.go3
-rw-r--r--pkg/gui/controllers/helpers/app_status_helper.go9
-rw-r--r--pkg/gui/controllers/helpers/cherry_pick_helper.go3
-rw-r--r--pkg/gui/controllers/helpers/gpg_helper.go3
-rw-r--r--pkg/gui/controllers/helpers/refresh_helper.go7
-rw-r--r--pkg/gui/controllers/helpers/refs_helper.go3
-rw-r--r--pkg/gui/controllers/helpers/suggestions_helper.go3
-rw-r--r--pkg/gui/controllers/helpers/update_helper.go5
-rw-r--r--pkg/gui/controllers/local_commits_controller.go27
-rw-r--r--pkg/gui/controllers/remote_branches_controller.go5
-rw-r--r--pkg/gui/controllers/remotes_controller.go5
-rw-r--r--pkg/gui/controllers/sub_commits_controller.go3
-rw-r--r--pkg/gui/controllers/submodules_controller.go15
-rw-r--r--pkg/gui/controllers/sync_controller.go24
-rw-r--r--pkg/gui/controllers/tags_controller.go5
-rw-r--r--pkg/gui/controllers/undo_controller.go5
-rw-r--r--pkg/gui/gui.go14
-rw-r--r--pkg/gui/gui_common.go2
-rw-r--r--pkg/gui/popup/fake_popup_handler.go13
-rw-r--r--pkg/gui/popup/popup_handler.go16
-rw-r--r--pkg/gui/services/custom_commands/handler_creator.go3
-rw-r--r--pkg/gui/tasks_adapter.go5
-rw-r--r--pkg/gui/types/common.go6
-rw-r--r--pkg/tasks/async_handler.go7
-rw-r--r--pkg/tasks/async_handler_test.go5
-rw-r--r--pkg/tasks/tasks.go38
-rw-r--r--pkg/tasks/tasks_test.go11
38 files changed, 199 insertions, 172 deletions
diff --git a/pkg/commands/git_commands/remote.go b/pkg/commands/git_commands/remote.go
index b594db28c..4366ba539 100644
--- a/pkg/commands/git_commands/remote.go
+++ b/pkg/commands/git_commands/remote.go
@@ -2,6 +2,8 @@ package git_commands
import (
"fmt"
+
+ "github.com/jesseduffield/gocui"
)
type RemoteCommands struct {
@@ -46,12 +48,12 @@ func (self *RemoteCommands) UpdateRemoteUrl(remoteName string, updatedUrl string
return self.cmd.New(cmdArgs).Run()
}
-func (self *RemoteCommands) DeleteRemoteBranch(remoteName string, branchName string) error {
+func (self *RemoteCommands) DeleteRemoteBranch(task *gocui.Task, remoteName string, branchName string) error {
cmdArgs := NewGitCmd("push").
Arg(remoteName, "--delete", branchName).
ToArgv()
- return self.cmd.New(cmdArgs).PromptOnCredentialRequest().WithMutex(self.syncMutex).Run()
+ return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
}
// CheckRemoteBranchExists Returns remote branch
diff --git a/pkg/commands/git_commands/sync.go b/pkg/commands/git_commands/sync.go
index dc0a0c68c..901133c4d 100644
--- a/pkg/commands/git_commands/sync.go
+++ b/pkg/commands/git_commands/sync.go
@@ -2,6 +2,7 @@ package git_commands
import (
"github.com/go-errors/errors"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
)
@@ -23,7 +24,7 @@ type PushOpts struct {
SetUpstream bool
}
-func (self *SyncCommands) PushCmdObj(opts PushOpts) (oscommands.ICmdObj, error) {
+func (self *SyncCommands) PushCmdObj(task *gocui.Task, opts PushOpts) (oscommands.ICmdObj, error) {
if opts.UpstreamBranch != "" && opts.UpstreamRemote == "" {
return nil, errors.New(self.Tr.MustSpecifyOriginError)
}
@@ -35,12 +36,12 @@ func (self *SyncCommands) PushCmdObj(opts PushOpts) (oscommands.ICmdObj, error)
ArgIf(opts.UpstreamBranch != "", opts.UpstreamBranch).
ToArgv()
- cmdObj := self.cmd.New(cmdArgs).PromptOnCredentialRequest().WithMutex(self.syncMutex)
+ cmdObj := self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex)
return cmdObj, nil
}
-func (self *SyncCommands) Push(opts PushOpts) error {
- cmdObj, err := self.PushCmdObj(opts)
+func (self *SyncCommands) Push(task *gocui.Task, opts PushOpts) error {
+ cmdObj, err := self.PushCmdObj(task, opts)
if err != nil {
return err
}
@@ -48,28 +49,24 @@ func (self *SyncCommands) Push(opts PushOpts) error {
return cmdObj.Run()
}
-type FetchOptions struct {
- Background bool
-}
-
-// Fetch fetch git repo
-func (self *SyncCommands) FetchCmdObj(opts FetchOptions) oscommands.ICmdObj {
+func (self *SyncCommands) Fetch(task *gocui.Task) error {
cmdArgs := NewGitCmd("fetch").
ArgIf(self.UserConfig.Git.FetchAll, "--all").
ToArgv()
cmdObj := self.cmd.New(cmdArgs)
- if opts.Background {
- cmdObj.DontLog().FailOnCredentialRequest()
- } else {
- cmdObj.PromptOnCredentialRequest()
- }
- return cmdObj.WithMutex(self.syncMutex)
+ cmdObj.PromptOnCredentialRequest(task)
+ return cmdObj.WithMutex(self.syncMutex).Run()
}
-func (self *SyncCommands) Fetch(opts FetchOptions) error {
- cmdObj := self.FetchCmdObj(opts)
- return cmdObj.Run()
+func (self *SyncCommands) FetchBackground() error {
+ cmdArgs := NewGitCmd("fetch").
+ ArgIf(self.UserConfig.Git.FetchAll, "--all").
+ ToArgv()
+
+ cmdObj := self.cmd.New(cmdArgs)
+ cmdObj.DontLog().FailOnCredentialRequest()
+ return cmdObj.WithMutex(self.syncMutex).Run()
}
type PullOptions struct {
@@ -78,7 +75,7 @@ type PullOptions struct {
FastForwardOnly bool
}
-func (self *SyncCommands) Pull(opts PullOptions) error {
+func (self *SyncCommands) Pull(task *gocui.Task, opts PullOptions) error {
cmdArgs := NewGitCmd("pull").
Arg("--no-edit").
ArgIf(opts.FastForwardOnly, "--ff-only").
@@ -88,22 +85,22 @@ func (self *SyncCommands) Pull(opts PullOptions) error {
// setting GIT_SEQUENCE_EDITOR to ':' as a way of skipping it, in case the user
// has 'pull.rebase = interactive' configured.
- return self.cmd.New(cmdArgs).AddEnvVars("GIT_SEQUENCE_EDITOR=:").PromptOnCredentialRequest().WithMutex(self.syncMutex).Run()
+ return self.cmd.New(cmdArgs).AddEnvVars("GIT_SEQUENCE_EDITOR=:").PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
}
-func (self *SyncCommands) FastForward(branchName string, remoteName string, remoteBranchName string) error {
+func (self *SyncCommands) FastForward(task *gocui.Task, branchName string, remoteName string, remoteBranchName string) error {
cmdArgs := NewGitCmd("fetch").
Arg(remoteName).
Arg(remoteBranchName + ":" + branchName).
ToArgv()
- return self.cmd.New(cmdArgs).PromptOnCredentialRequest().WithMutex(self.syncMutex).Run()
+ return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
}
-func (self *SyncCommands) FetchRemote(remoteName string) error {
+func (self *SyncCommands) FetchRemote(task *gocui.Task, remoteName string) error {
cmdArgs := NewGitCmd("fetch").
Arg(remoteName).
ToArgv()
- return self.cmd.New(cmdArgs).PromptOnCredentialRequest().WithMutex(self.syncMutex).Run()
+ return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
}
diff --git a/pkg/commands/git_commands/tag.go b/pkg/commands/git_commands/tag.go
index f399a578a..e58e81d07 100644
--- a/pkg/commands/git_commands/tag.go
+++ b/pkg/commands/git_commands/tag.go
@@ -1,5 +1,7 @@
package git_commands
+import "github.com/jesseduffield/gocui"
+
type TagCommands struct {
*GitCommon
}
@@ -34,9 +36,9 @@ func (self *TagCommands) Delete(tagName string) error {
return self.cmd.New(cmdArgs).Run()
}
-func (self *TagCommands) Push(remoteName string, tagName string) error {
+func (self *TagCommands) Push(task *gocui.Task, remoteName string, tagName string) error {
cmdArgs := NewGitCmd("push").Arg(remoteName, "tag", tagName).
ToArgv()
- return self.cmd.New(cmdArgs).PromptOnCredentialRequest().WithMutex(self.syncMutex).Run()
+ return self.cmd.New(cmdArgs).PromptOnCredentialRequest(task).WithMutex(self.syncMutex).Run()
}
diff --git a/pkg/commands/oscommands/cmd_obj.go b/pkg/commands/oscommands/cmd_obj.go
index b1223ea00..a46fe9699 100644
--- a/pkg/commands/oscommands/cmd_obj.go
+++ b/pkg/commands/oscommands/cmd_obj.go
@@ -4,6 +4,7 @@ import (
"os/exec"
"strings"
+ "github.com/jesseduffield/gocui"
"github.com/samber/lo"
"github.com/sasha-s/go-deadlock"
)
@@ -56,13 +57,14 @@ type ICmdObj interface {
// returns true if IgnoreEmptyError() was called
ShouldIgnoreEmptyError() bool
- PromptOnCredentialRequest() ICmdObj
+ PromptOnCredentialRequest(task *gocui.Task) ICmdObj
FailOnCredentialRequest() ICmdObj
WithMutex(mutex *deadlock.Mutex) ICmdObj
Mutex() *deadlock.Mutex
GetCredentialStrategy() CredentialStrategy
+ GetTask() *gocui.Task
}
type CmdObj struct {
@@ -85,6 +87,7 @@ type CmdObj struct {
// if set to true, it means we might be asked to enter a username/password by this command.
credentialStrategy CredentialStrategy
+ task *gocui.Task
// can be set so that we don't run certain commands simultaneously
mutex *deadlock.Mutex
@@ -192,8 +195,9 @@ func (self *CmdObj) RunAndProcessLines(onLine func(line string) (bool, error)) e
return self.runner.RunAndProcessLines(self, onLine)
}
-func (self *CmdObj) PromptOnCredentialRequest() ICmdObj {
+func (self *CmdObj) PromptOnCredentialRequest(task *gocui.Task) ICmdObj {
self.credentialStrategy = PROMPT
+ self.task = task
return self
}
@@ -207,3 +211,7 @@ func (self *CmdObj) FailOnCredentialRequest() ICmdObj {
func (self *CmdObj) GetCredentialStrategy() CredentialStrategy {
return self.credentialStrategy
}
+
+func (self *CmdObj) GetTask() *gocui.Task {
+ return self.task
+}
diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go
index 55cf1e1ce..fc1c55f05 100644
--- a/pkg/commands/oscommands/cmd_obj_runner.go
+++ b/pkg/commands/oscommands/cmd_obj_runner.go
@@ -8,6 +8,7 @@ import (
"strings"
"github.com/go-errors/errors"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/sirupsen/logrus"
)
@@ -308,7 +309,7 @@ func (self *cmdObjRunner) runAndDetectCredentialRequest(
tr := io.TeeReader(handler.stdoutPipe, cmdWriter)
go utils.Safe(func() {
- self.processOutput(tr, handler.stdinPipe, promptUserForCredential)
+ self.processOutput(tr, handler.stdinPipe, promptUserForCredential, cmdObj.GetTask())
})
})
}
@@ -317,6 +318,7 @@ func (self *cmdObjRunner) processOutput(
reader io.Reader,
writer io.Writer,
promptUserForCredential func(CredentialType) <-chan string,
+ task *gocui.Task,
) {
checkForCredentialRequest := self.getCheckForCredentialRequestFunc()
@@ -327,13 +329,9 @@ func (self *cmdObjRunner) processOutput(
askFor, ok := checkForCredentialRequest(newBytes)
if ok {
responseChan := promptUserForCredential(askFor)
- // We assume that the busy count is greater than zero here because we're
- // in the middle of a command. We decrement it so that The user can be prompted
- // without lazygit thinking it's still doing its own processing. This helps
- // integration tests know how long to wait before typing in a response.
- self.guiIO.DecrementBusyCount()
+ task.Pause()
toInput := <-responseChan
- self.guiIO.IncrementBusyCount()
+ task.Continue()
// If the return data is empty we don't write anything to stdin
if toInput != "" {
_, _ = writer.Write([]byte(toInput))
diff --git a/pkg/commands/oscommands/gui_io.go b/pkg/commands/oscommands/gui_io.go
index 1ff090052..6a6198310 100644
--- a/pkg/commands/oscommands/gui_io.go
+++ b/pkg/commands/oscommands/gui_io.go
@@ -27,9 +27,6 @@ type guiIO struct {
// that a command requests it.
// the 'credential' arg is something like 'username' or 'password'
promptForCredentialFn func(credential CredentialType) <-chan string
-
- IncrementBusyCount func()
- DecrementBusyCount func()
}
func NewGuiIO(
@@ -37,16 +34,12 @@ func NewGuiIO(
logCommandFn func(string, bool),
newCmdWriterFn func() io.Writer,
promptForCredentialFn func(CredentialType) <-chan string,
- IncrementBusyCount func(),
- DecrementBusyCount func(),
) *guiIO {
return &guiIO{
log: log,
logCommandFn: logCommandFn,
newCmdWriterFn: newCmdWriterFn,
promptForCredentialFn: promptForCredentialFn,
- IncrementBusyCount: IncrementBusyCount,
- DecrementBusyCount: DecrementBusyCount,
}
}
@@ -58,7 +51,5 @@ func NewNullGuiIO(log *logrus.Entry) *guiIO {
logCommandFn: func(string, bool) {},
newCmdWriterFn: func() io.Writer { return io.Discard },
promptForCredentialFn: failPromptFn,
- IncrementBusyCount: func() {},
- DecrementBusyCount: func() {},
}
}
diff --git a/pkg/gui/background.go b/pkg/gui/background.go
index d789f1790..3417d67bf 100644
--- a/pkg/gui/background.go
+++ b/pkg/gui/background.go
@@ -4,7 +4,7 @@ import (
"strings"
"time"
- "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -86,7 +86,7 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru
if self.pauseBackgroundRefreshes {
continue
}
- self.gui.c.OnWorker(func() { _ = function() })
+ self.gui.c.OnWorker(func(*gocui.Task) { _ = function() })
case <-stop:
return
}
@@ -95,7 +95,7 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru
}
func (self *BackgroundRoutineMgr) backgroundFetch() (err error) {
- err = self.gui.git.Sync.Fetch(git_commands.FetchOptions{Background: true})
+ err = self.gui.git.Sync.FetchBackground()
_ = self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS}, Mode: types.ASYNC})
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go
index 972ea6090..d0ef6ee69 100644
--- a/pkg/gui/controllers/branches_controller.go
+++ b/pkg/gui/controllers/branches_controller.go
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
@@ -363,11 +364,12 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
},
)
- return self.c.WithLoaderPanel(message, func() error {
+ return self.c.WithLoaderPanel(message, func(task *gocui.Task) error {
if branch == self.c.Helpers().Refs.GetCheckedOutRef() {
self.c.LogAction(action)
err := self.c.Git().Sync.Pull(
+ task,
git_commands.PullOptions{
RemoteName: branch.UpstreamRemote,
BranchName: branch.UpstreamBranch,
@@ -381,7 +383,7 @@ func (self *BranchesController) fastForward(branch *models.Branch) error {
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
} else {
self.c.LogAction(action)
- err := self.c.Git().Sync.FastForward(branch.Name, branch.UpstreamRemote, branch.UpstreamBranch)
+ err := self.c.Git().Sync.FastForward(task, branch.Name, branch.UpstreamRemote, branch.UpstreamBranch)
if err != nil {
_ = self.c.Error(err)
}
diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go
index 745186df0..f7208012e 100644
--- a/pkg/gui/controllers/commits_files_controller.go
+++ b/pkg/gui/controllers/commits_files_controller.go
@@ -177,7 +177,7 @@ func (self *CommitFilesController) discard(node *filetree.CommitFileNode) error
Title: self.c.Tr.DiscardFileChangesTitle,
Prompt: prompt,
HandleConfirm: func() error {
- return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(*gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.DiscardOldFileChange)
if err := self.c.Git().Rebase.DiscardOldFileChanges(self.c.Model().Commits, self.c.Contexts().LocalCommits.GetSelectedLineIdx(), node.GetPath()); err != nil {
if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil {
@@ -205,7 +205,7 @@ func (self *CommitFilesController) edit(node *filetree.CommitFileNode) error {
func (self *CommitFilesController) toggleForPatch(node *filetree.CommitFileNode) error {
toggle := func() error {
- return self.c.WithWaitingStatus(self.c.Tr.UpdatingPatch, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.UpdatingPatch, func(*gocui.Task) error {
if !self.c.Git().Patch.PatchBuilder.Active() {
if err := self.startPatchBuilder(); err != nil {
return err
diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go
index a511348bb..b4a35b43a 100644
--- a/pkg/gui/controllers/custom_patch_options_menu_action.go
+++ b/pkg/gui/controllers/custom_patch_options_menu_action.go
@@ -3,6 +3,7 @@ package controllers
import (
"fmt"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -116,7 +117,7 @@ func (self *CustomPatchOptionsMenuAction) handleDeletePatchFromCommit() error {
return err
}
- return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(*gocui.Task) error {
commitIndex := self.getPatchCommitIndex()
self.c.LogAction(self.c.Tr.Actions.RemovePatchFromCommit)
err := self.c.Git().Patch.DeletePatchesFromCommit(self.c.Model().Commits, commitIndex)
@@ -133,7 +134,7 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchToSelectedCommit() erro
return err
}
- return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(*gocui.Task) error {
commitIndex := self.getPatchCommitIndex()
self.c.LogAction(self.c.Tr.Actions.MovePatchToSelectedCommit)
err := self.c.Git().Patch.MovePatchToSelectedCommit(self.c.Model().Commits, commitIndex, self.c.Contexts().LocalCommits.GetSelectedLineIdx())
@@ -151,7 +152,7 @@ func (self *CustomPatchOptionsMenuAction) handleMovePatchIntoWorkingTree() error
}
pull := func(stash bool) error {
- return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(*gocui.Task) error {
commitIndex := self.getPatchCommitIndex()
self.c.LogAction(self.c.Tr.Actions.MovePatchIntoIndex)
err := self.c.Git().Patch.MovePatchIntoIndex(self.c.Model().Commits, commitIndex, stash)
@@ -181,7 +182,7 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
return err
}
- return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(*gocui.Task) error {
commitIndex := self.getPatchCommitIndex()
self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex)
diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go
index 61d91ad69..8f43162cf 100644
--- a/pkg/gui/controllers/files_controller.go
+++ b/pkg/gui/controllers/files_controller.go
@@ -4,7 +4,6 @@ import (
"strings"
"github.com/jesseduffield/gocui"
- "github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
@@ -801,17 +800,17 @@ func (self *FilesController) onClickSecondary(opts gocui.ViewMouseBindingOpts) e
}
func (self *FilesController) fetch() error {
- return self.c.WithLoaderPanel(self.c.Tr.FetchWait, func() error {
- if err := self.fetchAux(); err != nil {
+ return self.c.WithLoaderPanel(self.c.Tr.FetchWait, func(task *gocui.Task) error {
+ if err := self.fetchAux(task); err != nil {
_ = self.c.Error(err)
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
})
}
-func (self *FilesController) fetchAux() (err error) {
+func (self *FilesController) fetchAux(task *gocui.Task) (err error) {
self.c.LogAction("Fetch")
- err = self.c.Git().Sync.Fetch(git_commands.FetchOptions{})
+ err = self.c.Git().Sync.Fetch(task)
if err != nil && strings.Contains(err.Error(), "exit status 128") {
_ = self.c.ErrorMsg(self.c.Tr.PassUnameWrong)
diff --git a/pkg/gui/controllers/files_remove_controller.go b/pkg/gui/controllers/files_remove_controller.go
index f25ae1209..8e1751c64 100644
--- a/pkg/gui/controllers/files_remove_controller.go
+++ b/pkg/gui/controllers/files_remove_controller.go
@@ -1,6 +1,7 @@
package controllers
import (
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
@@ -145,7 +146,7 @@ func (self *FilesRemoveController) remove(node *filetree.FileNode) error {
}
func (self *FilesRemoveController) ResetSubmodule(submodule *models.SubmoduleConfig) error {
- return self.c.WithWaitingStatus(self.c.Tr.ResettingSubmoduleStatus, func() error {
+ return self.c.WithWaitingStatus(self.c.Tr.ResettingSubmoduleStatus, func(*gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.ResetSubmodule)
file := self.c.Helpers().WorkingTree.FileForSubmodule(submodule)
diff --git a/pkg/gui/controllers/helpers/app_status_helper.go b/pkg/gui/controllers/helpers/app_status_helper.go
index dcac41e48..e271e1999 100644
--- a/pkg/gui/controllers/helpers/app_status_helper.go
+++ b/pkg/gui/controllers/helpers/app_status_helper.go
@@ -3,6 +3,7 @@ package helpers
import (
"time"
+ "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/status"
)
@@ -26,12 +27,12 @@ func (self *AppStatusHelper) Toast(message string) {
}
// withWaitingStatus wraps a function and shows a waiting status while the function is still executing
-func (self *AppStatusHelper) WithWaitingStatus(message string, f func() error) {
- self.c.OnWorker(func() {
+func (self *AppStatusHelper) WithWaitingStatus(message string, f func(*gocui.Task) error) {
+ self.c.OnWorker(func(task *gocui.Task) {
self.statusMgr().WithWaitingStatus(message, func() {
self.renderAppStatus()
- if err := f(); err != nil {
+ if err := f(task); err != nil {
self.c.OnUIThread(func() error {
return self.c.Error(err)
})
@@ -49,7 +50,7 @@ func (self *AppStatusHelper) GetStatusString() string {
}
func (self *AppStatusHelper) renderAppStatus() {
- self.c.OnWorker(func() {
+ self.c.OnWorker(func(_ *gocui.Task) {
ticker := time.NewTicker(time.Millisecond * 50)
defer ticker.Stop()
for range ticker.C {
diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go
index 2c9b7c7c9..9797b3ef3 100644
--- a/pkg/gui/controllers/helpers/cherry_pick_helper.go
+++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go
@@ -1,6 +