From 9f80d1d578b8f0bcbd67cbf461aa912155fdf0ca Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 3 Jan 2025 18:42:50 -0800 Subject: [PATCH] Fix no branch redirection loop --- options/locale/locale_en-US.ini | 1 + routers/web/repo/view_home.go | 5 +++++ templates/repo/empty.tmpl | 12 +++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6029d49ade0bc..07c9ffa9fc5ad 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1235,6 +1235,7 @@ create_new_repo_command = Creating a new repository on the command line push_exist_repo = Pushing an existing repository from the command line empty_message = This repository does not contain any content. broken_message = The Git data underlying this repository cannot be read. Contact the administrator of this instance or delete this repository. +no_branch = This repository doesn’t have any branches. code = Code code.desc = Access source code, files, commits and branches. diff --git a/routers/web/repo/view_home.go b/routers/web/repo/view_home.go index 70ba07f9a89a3..533b588bba18e 100644 --- a/routers/web/repo/view_home.go +++ b/routers/web/repo/view_home.go @@ -240,6 +240,11 @@ func handleRepoEmptyOrBroken(ctx *context.Context) { return } + if v, ok := ctx.Data["BranchesCount"]; ok && v.(int64) == 0 { + ctx.HTML(http.StatusOK, tplRepoEMPTY) + return + } + // the repo is not really empty, so we should update the modal in database // such problem may be caused by: // 1) an error occurs during pushing/receiving. 2) the user replaces an empty git repo manually diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl index 7170fe360203d..5e2b7e6a6fbd5 100644 --- a/templates/repo/empty.tmpl +++ b/templates/repo/empty.tmpl @@ -15,9 +15,15 @@ {{end}} {{if .Repository.IsBroken}} -
- {{ctx.Locale.Tr "repo.broken_message"}} -
+ {{if (not .BranchesCount)}} +
+ {{ctx.Locale.Tr "repo.no_branch"}} +
+ {{else}} +
+ {{ctx.Locale.Tr "repo.broken_message"}} +
+ {{end}} {{else if .CanWriteCode}}

{{ctx.Locale.Tr "repo.quick_guide"}}