diff options
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/remote.go | 6 | ||||
-rw-r--r-- | pkg/commands/git_commands/sync.go | 47 | ||||
-rw-r--r-- | pkg/commands/git_commands/tag.go | 6 | ||||
-rw-r--r-- | pkg/commands/oscommands/cmd_obj.go | 12 | ||||
-rw-r--r-- | pkg/commands/oscommands/cmd_obj_runner.go | 12 | ||||
-rw-r--r-- | pkg/commands/oscommands/gui_io.go | 9 |
6 files changed, 45 insertions, 47 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() {}, } } |