From 2b64762a32bceda5de4efeb1bc1b520b334c46d7 Mon Sep 17 00:00:00 2001 From: Minjie Fang Date: Sun, 10 May 2026 01:28:06 +0000 Subject: [PATCH] Fix login edit to check config existence (#987) Fix https://gitea.com/gitea/tea/issues/561 Reviewed-on: https://gitea.com/gitea/tea/pulls/987 Reviewed-by: Lunny Xiao Co-authored-by: Minjie Fang Co-committed-by: Minjie Fang --- cmd/login/edit.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/login/edit.go b/cmd/login/edit.go index a052ba3..bf98982 100644 --- a/cmd/login/edit.go +++ b/cmd/login/edit.go @@ -5,11 +5,13 @@ package login import ( "context" + "fmt" "os" "os/exec" "code.gitea.io/tea/cmd/flags" "code.gitea.io/tea/modules/config" + "code.gitea.io/tea/modules/utils" "github.com/skratchdot/open-golang/open" "github.com/urfave/cli/v3" @@ -27,12 +29,17 @@ var CmdLoginEdit = cli.Command{ } func runLoginEdit(_ context.Context, _ *cli.Command) error { + ymlPath := config.GetConfigPath() if e, ok := os.LookupEnv("EDITOR"); ok && e != "" { - cmd := exec.Command(e, config.GetConfigPath()) + cmd := exec.Command(e, ymlPath) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() } - return open.Start(config.GetConfigPath()) + if exist, _ := utils.FileExist(ymlPath); !exist { + fmt.Printf("Config file does not exist, please run login add first\n") + return nil + } + return open.Start(ymlPath) }