forked from gitea/gitea

Backport #27713 by @silverwind Fixes: https://github.com/go-gitea/gitea/issues/27600  Also tested together with https://github.com/go-gitea/gitea/pull/27704, works well. Co-authored-by: silverwind <me@silverwind.io>