mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
fix bug that caused credentials popup to be raised unexpectedly
This commit is contained in:
@ -24,9 +24,9 @@ var _ ICmdObjRunner = &cmdObjRunner{}
|
|||||||
func (self *cmdObjRunner) runWithCredentialHandling(cmdObj ICmdObj) error {
|
func (self *cmdObjRunner) runWithCredentialHandling(cmdObj ICmdObj) error {
|
||||||
switch cmdObj.GetCredentialStrategy() {
|
switch cmdObj.GetCredentialStrategy() {
|
||||||
case PROMPT:
|
case PROMPT:
|
||||||
return self.RunCommandWithOutputLive(cmdObj, self.guiIO.promptForCredentialFn)
|
return self.RunAndDetectCredentialRequest(cmdObj, self.guiIO.promptForCredentialFn)
|
||||||
case FAIL:
|
case FAIL:
|
||||||
return self.RunCommandWithOutputLive(cmdObj, func(s string) string { return "\n" })
|
return self.RunAndDetectCredentialRequest(cmdObj, func(CredentialName) string { return "\n" })
|
||||||
}
|
}
|
||||||
|
|
||||||
// we should never land here
|
// we should never land here
|
||||||
|
@ -13,15 +13,23 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CredentialName string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Password CredentialName = "password"
|
||||||
|
Username = "username"
|
||||||
|
Passphrase = "passphrase"
|
||||||
|
)
|
||||||
|
|
||||||
// RunAndDetectCredentialRequest detect a username / password / passphrase question in a command
|
// RunAndDetectCredentialRequest detect a username / password / passphrase question in a command
|
||||||
// promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase
|
// promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase
|
||||||
// The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
|
// The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
|
||||||
func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(string) string) error {
|
func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialName) string) error {
|
||||||
ttyText := ""
|
ttyText := ""
|
||||||
err := self.RunCommandWithOutputLive(cmdObj, func(word string) string {
|
err := self.RunCommandWithOutputLive(cmdObj, func(word string) string {
|
||||||
ttyText = ttyText + " " + word
|
ttyText = ttyText + " " + word
|
||||||
|
|
||||||
prompts := map[string]string{
|
prompts := map[string]CredentialName{
|
||||||
`.+'s password:`: "password",
|
`.+'s password:`: "password",
|
||||||
`Password\s*for\s*'.+':`: "password",
|
`Password\s*for\s*'.+':`: "password",
|
||||||
`Username\s*for\s*'.+':`: "username",
|
`Username\s*for\s*'.+':`: "username",
|
||||||
|
@ -27,10 +27,10 @@ type guiIO struct {
|
|||||||
// this allows us to request info from the user like username/password, in the event
|
// this allows us to request info from the user like username/password, in the event
|
||||||
// that a command requests it.
|
// that a command requests it.
|
||||||
// the 'credential' arg is something like 'username' or 'password'
|
// the 'credential' arg is something like 'username' or 'password'
|
||||||
promptForCredentialFn func(credential string) string
|
promptForCredentialFn func(credential CredentialName) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(string) string) *guiIO {
|
func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(CredentialName) string) *guiIO {
|
||||||
return &guiIO{
|
return &guiIO{
|
||||||
log: log,
|
log: log,
|
||||||
logCommandFn: logCommandFn,
|
logCommandFn: logCommandFn,
|
||||||
@ -44,6 +44,6 @@ func NewNullGuiIO(log *logrus.Entry) *guiIO {
|
|||||||
log: log,
|
log: log,
|
||||||
logCommandFn: func(string, bool) {},
|
logCommandFn: func(string, bool) {},
|
||||||
newCmdWriterFn: func() io.Writer { return ioutil.Discard },
|
newCmdWriterFn: func() io.Writer { return ioutil.Discard },
|
||||||
promptForCredentialFn: func(string) string { return "" },
|
promptForCredentialFn: func(CredentialName) string { return "" },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type credentials chan string
|
type credentials chan string
|
||||||
|
|
||||||
// promptUserForCredential wait for a username, password or passphrase input from the credentials popup
|
// promptUserForCredential wait for a username, password or passphrase input from the credentials popup
|
||||||
func (gui *Gui) promptUserForCredential(passOrUname string) string {
|
func (gui *Gui) promptUserForCredential(passOrUname oscommands.CredentialName) string {
|
||||||
gui.credentials = make(chan string)
|
gui.credentials = make(chan string)
|
||||||
gui.g.Update(func(g *gocui.Gui) error {
|
gui.g.Update(func(g *gocui.Gui) error {
|
||||||
credentialsView := gui.Views.Credentials
|
credentialsView := gui.Views.Credentials
|
||||||
@ -21,7 +22,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
|
|||||||
case "password":
|
case "password":
|
||||||
credentialsView.Title = gui.Tr.CredentialsPassword
|
credentialsView.Title = gui.Tr.CredentialsPassword
|
||||||
credentialsView.Mask = '*'
|
credentialsView.Mask = '*'
|
||||||
default:
|
case "passphrase":
|
||||||
credentialsView.Title = gui.Tr.CredentialsPassphrase
|
credentialsView.Title = gui.Tr.CredentialsPassphrase
|
||||||
credentialsView.Mask = '*'
|
credentialsView.Mask = '*'
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user