mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 20:36:03 +02:00
fix bug that caused credentials popup to be raised unexpectedly
This commit is contained in:
parent
0dd1c12e2f
commit
fdf79fdeee
4 changed files with 18 additions and 9 deletions
|
@ -24,9 +24,9 @@ var _ ICmdObjRunner = &cmdObjRunner{}
|
|||
func (self *cmdObjRunner) runWithCredentialHandling(cmdObj ICmdObj) error {
|
||||
switch cmdObj.GetCredentialStrategy() {
|
||||
case PROMPT:
|
||||
return self.RunCommandWithOutputLive(cmdObj, self.guiIO.promptForCredentialFn)
|
||||
return self.RunAndDetectCredentialRequest(cmdObj, self.guiIO.promptForCredentialFn)
|
||||
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
|
||||
|
|
|
@ -13,15 +13,23 @@ import (
|
|||
"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
|
||||
// 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
|
||||
func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(string) string) error {
|
||||
func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialName) string) error {
|
||||
ttyText := ""
|
||||
err := self.RunCommandWithOutputLive(cmdObj, func(word string) string {
|
||||
ttyText = ttyText + " " + word
|
||||
|
||||
prompts := map[string]string{
|
||||
prompts := map[string]CredentialName{
|
||||
`.+'s password:`: "password",
|
||||
`Password\s*for\s*'.+':`: "password",
|
||||
`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
|
||||
// that a command requests it.
|
||||
// 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{
|
||||
log: log,
|
||||
logCommandFn: logCommandFn,
|
||||
|
@ -44,6 +44,6 @@ func NewNullGuiIO(log *logrus.Entry) *guiIO {
|
|||
log: log,
|
||||
logCommandFn: func(string, bool) {},
|
||||
newCmdWriterFn: func() io.Writer { return ioutil.Discard },
|
||||
promptForCredentialFn: func(string) string { return "" },
|
||||
promptForCredentialFn: func(CredentialName) string { return "" },
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,14 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
type credentials chan string
|
||||
|
||||
// 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.g.Update(func(g *gocui.Gui) error {
|
||||
credentialsView := gui.Views.Credentials
|
||||
|
@ -21,7 +22,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
|
|||
case "password":
|
||||
credentialsView.Title = gui.Tr.CredentialsPassword
|
||||
credentialsView.Mask = '*'
|
||||
default:
|
||||
case "passphrase":
|
||||
credentialsView.Title = gui.Tr.CredentialsPassphrase
|
||||
credentialsView.Mask = '*'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue