summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-08 14:41:30 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-09 14:09:53 +1100
commitfdf79fdeee71b7f281a53c72c7a0be61136bef34 (patch)
tree2ca3dee952b42db6dd17ac6654c2b1cdbe8ea85b /pkg
parent0dd1c12e2f9cdf67a17058bab220ba30f7e74ed4 (diff)
fix bug that caused credentials popup to be raised unexpectedly
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/oscommands/cmd_obj_runner.go4
-rw-r--r--pkg/commands/oscommands/exec_live.go12
-rw-r--r--pkg/commands/oscommands/gui_io.go6
-rw-r--r--pkg/gui/credentials_panel.go5
4 files changed, 18 insertions, 9 deletions
diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go
index dbea23bf3..816e56ad6 100644
--- a/pkg/commands/oscommands/cmd_obj_runner.go
+++ b/pkg/commands/oscommands/cmd_obj_runner.go
@@ -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
diff --git a/pkg/commands/oscommands/exec_live.go b/pkg/commands/oscommands/exec_live.go
index 21c1c8d27..3526cdbd2 100644
--- a/pkg/commands/oscommands/exec_live.go
+++ b/pkg/commands/oscommands/exec_live.go
@@ -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",
diff --git a/pkg/commands/oscommands/gui_io.go b/pkg/commands/oscommands/gui_io.go
index ec42f90b3..5a174d46c 100644
--- a/pkg/commands/oscommands/gui_io.go
+++ b/pkg/commands/oscommands/gui_io.go
@@ -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 "" },
}
}
diff --git a/pkg/gui/credentials_panel.go b/pkg/gui/credentials_panel.go
index 2570a53e3..69c08359f 100644
--- a/pkg/gui/credentials_panel.go
+++ b/pkg/gui/credentials_panel.go
@@ -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 = '*'
}