aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2025-01-06 12:07:52 +0800
committerGitHub <noreply@github.com>2025-01-06 12:07:52 +0800
commit40765b5d45f1bcde7193b6273875707ff238cf92 (patch)
tree1a8f93bd8e98d0f2a467cfd74e59c16c19a54323
parent3c1c508421159970682c7d002bc8a180c8a1aeb7 (diff)
downloadgitea-40765b5d45f1bcde7193b6273875707ff238cf92.tar.gz
gitea-40765b5d45f1bcde7193b6273875707ff238cf92.zip
Fix repo empty guide (#33114)
-rw-r--r--routers/web/repo/view_home.go1
-rw-r--r--templates/repo/empty.tmpl2
-rw-r--r--tests/integration/empty_repo_test.go6
3 files changed, 7 insertions, 2 deletions
diff --git a/routers/web/repo/view_home.go b/routers/web/repo/view_home.go
index 3fcd7bba8e..f890225d67 100644
--- a/routers/web/repo/view_home.go
+++ b/routers/web/repo/view_home.go
@@ -250,6 +250,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
showEmpty = true // it is not really empty, but there is no branch
// at the moment, other repo units like "actions" are not able to handle such case,
// so we just mark the repo as empty to prevent from displaying these units.
+ ctx.Data["RepoHasContentsWithoutBranch"] = true
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
} else {
// the repo is actually not empty and has branches, need to update the database later
diff --git a/templates/repo/empty.tmpl b/templates/repo/empty.tmpl
index dfda5b7b2b..ae3f95045b 100644
--- a/templates/repo/empty.tmpl
+++ b/templates/repo/empty.tmpl
@@ -17,7 +17,7 @@
{{if .Repository.IsBroken}}
<div class="ui segment center">{{ctx.Locale.Tr "repo.broken_message"}}</div>
- {{else if .Repository.IsEmpty}}
+ {{else if .RepoHasContentsWithoutBranch}}
<div class="ui segment center">{{ctx.Locale.Tr "repo.no_branch"}}</div>
{{else if .CanWriteCode}}
<h4 class="ui top attached header">{{ctx.Locale.Tr "repo.quick_guide"}}</h4>
diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go
index 630a3c03af..0801b093df 100644
--- a/tests/integration/empty_repo_test.go
+++ b/tests/integration/empty_repo_test.go
@@ -58,8 +58,12 @@ func TestEmptyRepoAddFile(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user30")
- req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
+ req := NewRequest(t, "GET", "/user30/empty")
resp := session.MakeRequest(t, req, http.StatusOK)
+ assert.Contains(t, resp.Body.String(), "empty-repo-guide")
+
+ req = NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
+ resp = session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`)
assert.Empty(t, doc.AttrOr("checked", "_no_"))
req = NewRequestWithValues(t, "POST", "/user30/empty/_new/"+setting.Repository.DefaultBranch, map[string]string{