mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 22:33:07 +02:00
Close the pty instead of killing the process for runAndDetectCredentialRequest
As with the previous commit, this is not strictly necessary for anything, just cleaner.
This commit is contained in:
@ -336,7 +336,7 @@ func (self *cmdObjRunner) runAndDetectCredentialRequest(
|
|||||||
tr := io.TeeReader(handler.stdoutPipe, cmdWriter)
|
tr := io.TeeReader(handler.stdoutPipe, cmdWriter)
|
||||||
|
|
||||||
go utils.Safe(func() {
|
go utils.Safe(func() {
|
||||||
self.processOutput(tr, handler.stdinPipe, promptUserForCredential, cmdObj)
|
self.processOutput(tr, handler.stdinPipe, promptUserForCredential, handler.close, cmdObj)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -345,6 +345,7 @@ func (self *cmdObjRunner) processOutput(
|
|||||||
reader io.Reader,
|
reader io.Reader,
|
||||||
writer io.Writer,
|
writer io.Writer,
|
||||||
promptUserForCredential func(CredentialType) <-chan string,
|
promptUserForCredential func(CredentialType) <-chan string,
|
||||||
|
closeFunc func() error,
|
||||||
cmdObj *CmdObj,
|
cmdObj *CmdObj,
|
||||||
) {
|
) {
|
||||||
checkForCredentialRequest := self.getCheckForCredentialRequestFunc()
|
checkForCredentialRequest := self.getCheckForCredentialRequestFunc()
|
||||||
@ -358,14 +359,16 @@ func (self *cmdObjRunner) processOutput(
|
|||||||
if ok {
|
if ok {
|
||||||
responseChan := promptUserForCredential(askFor)
|
responseChan := promptUserForCredential(askFor)
|
||||||
if responseChan == nil {
|
if responseChan == nil {
|
||||||
// Returning a nil channel means we should kill the process.
|
// Returning a nil channel means we should terminate the process.
|
||||||
// Note that we don't break the loop after this, because we
|
// We achieve this by closing the pty that it's running in. Note that this won't
|
||||||
// still need to drain the output, otherwise the Wait() call
|
// work for the case where we're not running in a pty (i.e. on Windows), but
|
||||||
// later might block.
|
// in that case we'll never be prompted for credentials, so it's not a concern.
|
||||||
if err := Kill(cmdObj.GetCmd()); err != nil {
|
if err := closeFunc(); err != nil {
|
||||||
self.log.Error(err)
|
self.log.Error(err)
|
||||||
}
|
}
|
||||||
} else {
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if task != nil {
|
if task != nil {
|
||||||
task.Pause()
|
task.Pause()
|
||||||
}
|
}
|
||||||
@ -380,7 +383,6 @@ func (self *cmdObjRunner) processOutput(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// having a function that returns a function because we need to maintain some state inbetween calls hence the closure
|
// having a function that returns a function because we need to maintain some state inbetween calls hence the closure
|
||||||
func (self *cmdObjRunner) getCheckForCredentialRequestFunc() func([]byte) (CredentialType, bool) {
|
func (self *cmdObjRunner) getCheckForCredentialRequestFunc() func([]byte) (CredentialType, bool) {
|
||||||
|
@ -127,7 +127,7 @@ func TestProcessOutput(t *testing.T) {
|
|||||||
writer := &strings.Builder{}
|
writer := &strings.Builder{}
|
||||||
|
|
||||||
cmdObj := &CmdObj{task: gocui.NewFakeTask()}
|
cmdObj := &CmdObj{task: gocui.NewFakeTask()}
|
||||||
runner.processOutput(reader, writer, toChanFn(scenario.promptUserForCredential), cmdObj)
|
runner.processOutput(reader, writer, toChanFn(scenario.promptUserForCredential), func() error { return nil }, cmdObj)
|
||||||
|
|
||||||
if writer.String() != scenario.expectedToWrite {
|
if writer.String() != scenario.expectedToWrite {
|
||||||
t.Errorf("expected to write '%s' but got '%s'", scenario.expectedToWrite, writer.String())
|
t.Errorf("expected to write '%s' but got '%s'", scenario.expectedToWrite, writer.String())
|
||||||
|
Reference in New Issue
Block a user