From d643e94a690f0fc82d2b895a4233afd91c012301 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 11 Aug 2025 19:23:28 +0000 Subject: [PATCH] Fix tea login add with ssh public key bug (#789) Fix #705 Reviewed-on: https://gitea.com/gitea/tea/pulls/789 Reviewed-by: techknowlogick --- modules/interact/login.go | 7 ++++++- modules/interact/prompts.go | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/interact/login.go b/modules/interact/login.go index db0c53b..95e1729 100644 --- a/modules/interact/login.go +++ b/modules/interact/login.go @@ -168,7 +168,12 @@ func CreateLogin() error { printTitleAndContent("SSH Key/Certificate Path (leave empty for auto-discovery in ~/.ssh and ssh-agent):", sshKey) if sshKey == "" { - sshKey, err = promptSelect("Select ssh-key: ", task.ListSSHPubkey(), "", "", "") + pubKeys := task.ListSSHPubkey() + if len(pubKeys) == 0 { + fmt.Println("No SSH keys found in ~/.ssh or ssh-agent") + return nil + } + sshKey, err = promptSelect("Select ssh-key: ", pubKeys, "", "", "") if err != nil { return err } diff --git a/modules/interact/prompts.go b/modules/interact/prompts.go index d44d160..bb0ee9c 100644 --- a/modules/interact/prompts.go +++ b/modules/interact/prompts.go @@ -5,6 +5,7 @@ package interact import ( "fmt" + "slices" "strings" "time" @@ -125,7 +126,9 @@ func promptSelect(prompt string, options []string, customVal, noneVal, defaultVa if defaultVal == "" && noneVal != "" { defaultVal = noneVal } - + if len(options) > 0 && !slices.Contains(options, defaultVal) { + defaultVal = options[0] + } selection = defaultVal if err := huh.NewSelect[string](). Title(prompt).