1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

Add SSH key passphrase prompt to pull/push from/to remote git repo

This commit resolves issue with absence of ssh key prompting
to pull from or push to remote git repository.

I checked lazygit with this patch for successfully pull from
and push to https://gitweb.gentoo.org/repo/proj/guru.git repository.
While for lazygit-0.23.1 I'm not able to do that.

The check for Passphrase follows the Password because of
more long time before SSH key is prompt in terminal.
Otherwise after timeout "Password" prompt is appears.

Excuse me for google translated i18n dutch lines.

Bug: https://github.com/jesseduffield/lazygit/issues/534

Signed-off-by: band-a-prend <torokhov-s-a@yandex.ru>
This commit is contained in:
band-a-prend
2020-10-10 03:43:59 +03:00
committed by Jesse Duffield
parent a0963f8036
commit 582fd24d78
5 changed files with 21 additions and 13 deletions

View File

@ -143,18 +143,19 @@ func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string)
return RunCommandWithOutputLiveWrapper(c, command, output) return RunCommandWithOutputLiveWrapper(c, command, output)
} }
// DetectUnamePass detect a username / password question in a command // DetectUnamePass 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 // 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" or "password" and expects the user's password or username back // The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
func (c *OSCommand) DetectUnamePass(command string, promptUserForCredential func(string) string) error { func (c *OSCommand) DetectUnamePass(command string, promptUserForCredential func(string) string) error {
ttyText := "" ttyText := ""
errMessage := c.RunCommandWithOutputLive(command, func(word string) string { errMessage := c.RunCommandWithOutputLive(command, func(word string) string {
ttyText = ttyText + " " + word ttyText = ttyText + " " + word
prompts := map[string]string{ prompts := map[string]string{
`.+'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",
`Enter\s*passphrase\s*for\s*key\s*'.+':`: "passphrase",
} }
for pattern, askFor := range prompts { for pattern, askFor := range prompts {

View File

@ -9,7 +9,7 @@ import (
type credentials chan string type credentials chan string
// promptUserForCredential wait for a username or password 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 string) 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 {
@ -17,9 +17,12 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
if passOrUname == "username" { if passOrUname == "username" {
credentialsView.Title = gui.Tr.CredentialsUsername credentialsView.Title = gui.Tr.CredentialsUsername
credentialsView.Mask = 0 credentialsView.Mask = 0
} else { } else if passOrUname == "password" {
credentialsView.Title = gui.Tr.CredentialsPassword credentialsView.Title = gui.Tr.CredentialsPassword
credentialsView.Mask = '*' credentialsView.Mask = '*'
} else {
credentialsView.Title = gui.Tr.CredentialsPassphrase
credentialsView.Mask = '*'
} }
if err := gui.switchContext(gui.Contexts.Credentials.Context); err != nil { if err := gui.switchContext(gui.Contexts.Credentials.Context); err != nil {
@ -30,7 +33,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
return nil return nil
}) })
// wait for username/passwords input // wait for username/passwords/passphrase input
userInput := <-gui.credentials userInput := <-gui.credentials
return userInput + "\n" return userInput + "\n"
} }
@ -70,10 +73,10 @@ func (gui *Gui) handleCredentialsViewFocused() error {
func (gui *Gui) handleCredentialsPopup(cmdErr error) { func (gui *Gui) handleCredentialsPopup(cmdErr error) {
if cmdErr != nil { if cmdErr != nil {
errMessage := cmdErr.Error() errMessage := cmdErr.Error()
if strings.Contains(errMessage, "Invalid username or password") { if strings.Contains(errMessage, "Invalid username, password or passphrase") {
errMessage = gui.Tr.PassUnameWrong errMessage = gui.Tr.PassUnameWrong
} }
// we are not logging this error because it may contain a password // we are not logging this error because it may contain a password or a passphrase
gui.createErrorPanel(errMessage) gui.createErrorPanel(errMessage)
} else { } else {
_ = gui.closeConfirmationPrompt(false) _ = gui.closeConfirmationPrompt(false)

View File

@ -19,6 +19,7 @@ func dutchTranslationSet() TranslationSet {
CommitMessage: "Commit bericht", CommitMessage: "Commit bericht",
CredentialsUsername: "Gebruikersnaam", CredentialsUsername: "Gebruikersnaam",
CredentialsPassword: "Wachtwoord", CredentialsPassword: "Wachtwoord",
CredentialsPassphrase: "Voer een wachtwoordzin in voor de SSH-sleutel",
PassUnameWrong: "Wachtwoord en/of gebruikersnaam verkeert", PassUnameWrong: "Wachtwoord en/of gebruikersnaam verkeert",
CommitChanges: "Commit veranderingen", CommitChanges: "Commit veranderingen",
AmendLastCommit: "wijzig laatste commit", AmendLastCommit: "wijzig laatste commit",

View File

@ -30,6 +30,7 @@ type TranslationSet struct {
CommitMessage string CommitMessage string
CredentialsUsername string CredentialsUsername string
CredentialsPassword string CredentialsPassword string
CredentialsPassphrase string
PassUnameWrong string PassUnameWrong string
CommitChanges string CommitChanges string
AmendLastCommit string AmendLastCommit string
@ -519,7 +520,8 @@ func englishTranslationSet() TranslationSet {
CommitMessage: "Commit message", CommitMessage: "Commit message",
CredentialsUsername: "Username", CredentialsUsername: "Username",
CredentialsPassword: "Password", CredentialsPassword: "Password",
PassUnameWrong: "Password and/or username wrong", CredentialsPassphrase: "Enter passphrase for SSH key",
PassUnameWrong: "Password, passphrase and/or username wrong",
CommitChanges: "commit changes", CommitChanges: "commit changes",
AmendLastCommit: "amend last commit", AmendLastCommit: "amend last commit",
SureToAmend: "Are you sure you want to amend last commit? Afterwards, you can change commit message from the commits panel.", SureToAmend: "Are you sure you want to amend last commit? Afterwards, you can change commit message from the commits panel.",

View File

@ -15,7 +15,8 @@ func polishTranslationSet() TranslationSet {
CommitMessage: "Wiadomość commita", CommitMessage: "Wiadomość commita",
CredentialsUsername: "Username", CredentialsUsername: "Username",
CredentialsPassword: "Password", CredentialsPassword: "Password",
PassUnameWrong: "Password and/or username wrong", CredentialsPassphrase: "Passphrase",
PassUnameWrong: "Password, passphrase and/or username wrong",
CommitChanges: "commituj zmiany", CommitChanges: "commituj zmiany",
AmendLastCommit: "zmień ostatnie zatwierdzenie", AmendLastCommit: "zmień ostatnie zatwierdzenie",
SureToAmend: "Czy na pewno chcesz zmienić ostatnie zatwierdzenie? Możesz zmienić komunikat zatwierdzenia z panelu zatwierdzeń.", SureToAmend: "Czy na pewno chcesz zmienić ostatnie zatwierdzenie? Możesz zmienić komunikat zatwierdzenia z panelu zatwierdzeń.",