1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-27 23:08:02 +02:00

Kill background fetch when it requests a passphrase

Previously we would enter a newline at the password prompt, which would cause
the fetch to fail. The problem with this was that if you have many remotes, the
fetch would sometimes hang for some reason; I don't totally understand how that
happened, but I guess the many ssh processes requesting passwords would somehow
interfere with each other. Avoid this by simply killing the git fetch process
the moment it requests the first password.
This commit is contained in:
Stefan Haller 2025-05-23 14:55:31 +02:00
parent 52d34468d1
commit 1bb6ee0d80

View File

@ -294,14 +294,10 @@ const (
Token
)
// Whenever we're asked for a password we just enter a newline, which will
// eventually cause the command to fail.
// Whenever we're asked for a password we return a nil channel to tell the
// caller to kill the process.
var failPromptFn = func(CredentialType) <-chan string {
ch := make(chan string)
go func() {
ch <- "\n"
}()
return ch
return nil
}
func (self *cmdObjRunner) runWithCredentialHandling(cmdObj *CmdObj) error {
@ -360,16 +356,26 @@ func (self *cmdObjRunner) processOutput(
askFor, ok := checkForCredentialRequest(newBytes)
if ok {
responseChan := promptUserForCredential(askFor)
if task != nil {
task.Pause()
}
toInput := <-responseChan
if task != nil {
task.Continue()
}
// If the return data is empty we don't write anything to stdin
if toInput != "" {
_, _ = writer.Write([]byte(toInput))
if responseChan == nil {
// Returning a nil channel means we should kill the process.
// Note that we don't break the loop after this, because we
// still need to drain the output, otherwise the Wait() call
// later might block.
if err := Kill(cmdObj.GetCmd()); err != nil {
self.log.Error(err)
}
} else {
if task != nil {
task.Pause()
}
toInput := <-responseChan
if task != nil {
task.Continue()
}
// If the return data is empty we don't write anything to stdin
if toInput != "" {
_, _ = writer.Write([]byte(toInput))
}
}
}
}