From 6bddfd3086e198daf103e3db7234a04432ed8e40 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 20 Apr 2022 19:18:23 +0200 Subject: [PATCH] Warn on SSH connection for incorrect configuration (#19317) (#19437) Backport #19317 - 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. Co-authored-by: delvh Co-authored-by: wxiaoguang Co-authored-by: techknowlogick --- cmd/serv.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/serv.go b/cmd/serv.go index 5c3d512a37..9063a1c2c9 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -297,6 +297,15 @@ 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 `[repository]` `ROOT` was not found, please check if $GITEA_WORK_DIR is passed to the SSH connection or make `[repository]` `ROOT` an absolute value.") + } + } + gitcmd.Dir = setting.RepoRootPath gitcmd.Stdout = os.Stdout gitcmd.Stdin = os.Stdin