From 900f23402a1ac65d9740d46eb16b298b770398c3 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 4 Apr 2022 00:50:07 +0200 Subject: [PATCH 1/4] Warn on SSH connection for incorrect configuration - When `setting.RepoRootPath` cannot be found(most likely due to incorrect configuration) show "Gitea: Incorrect configuration" on the client-side to help easier with debugging the problem. --- cmd/serv.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/serv.go b/cmd/serv.go index c834ca298acff..0181160ddd8b6 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -296,6 +296,16 @@ func runServ(c *cli.Context) error { gitcmd = exec.CommandContext(ctx, verb, repoPath) } + // Check if setting.RepoRootPath exists. It could be the case that it doesn't exist, this can happen when + // `[repository]` `ROOT` is a relative path and $GITEA_WORK_DIR isn't passed to the SSH connection. + if _, err := os.Stat(setting.RepoRootPath); err != nil { + if os.IsNotExist(err) { + return fail("Incorrect configuration.", + "Directory %q was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` a absolute value.", + setting.RepoRootPath) + } + } + gitcmd.Dir = setting.RepoRootPath gitcmd.Stdout = os.Stdout gitcmd.Stdin = os.Stdin From 3306816e82b17e47bb235b5cdca9893c73852b8a Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 4 Apr 2022 22:30:33 -0400 Subject: [PATCH 2/4] Update cmd/serv.go Co-authored-by: delvh --- cmd/serv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/serv.go b/cmd/serv.go index 0181160ddd8b6..1c6a596d05ccc 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -301,7 +301,7 @@ func runServ(c *cli.Context) error { if _, err := os.Stat(setting.RepoRootPath); err != nil { if os.IsNotExist(err) { return fail("Incorrect configuration.", - "Directory %q was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` a absolute value.", + "Directory %q was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.", setting.RepoRootPath) } } From 2e477971969c24bde8532a4d80a96e52fa056ac0 Mon Sep 17 00:00:00 2001 From: Gusted Date: Tue, 5 Apr 2022 17:43:52 +0200 Subject: [PATCH 3/4] Don't leak configuration --- cmd/serv.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index 1c6a596d05ccc..606d3896320be 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -301,8 +301,7 @@ func runServ(c *cli.Context) error { if _, err := os.Stat(setting.RepoRootPath); err != nil { if os.IsNotExist(err) { return fail("Incorrect configuration.", - "Directory %q was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.", - setting.RepoRootPath) + "Directory "`[repository]` `ROOT`" was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.") } } From cfa9ba3559f1aeae5feecc812ce9e976d57950d3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 6 Apr 2022 00:01:17 +0800 Subject: [PATCH 4/4] Update cmd/serv.go --- cmd/serv.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/serv.go b/cmd/serv.go index 606d3896320be..b106d40d28d8f 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -301,7 +301,7 @@ func runServ(c *cli.Context) error { if _, err := os.Stat(setting.RepoRootPath); err != nil { if os.IsNotExist(err) { return fail("Incorrect configuration.", - "Directory "`[repository]` `ROOT`" was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.") + "Directory `[repository]` `ROOT` was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.") } }