Skip to content

Commit 40765b5

Browse files
authored
Fix repo empty guide (#33114)
1 parent 3c1c508 commit 40765b5

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

routers/web/repo/view_home.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
250250
showEmpty = true // it is not really empty, but there is no branch
251251
// at the moment, other repo units like "actions" are not able to handle such case,
252252
// so we just mark the repo as empty to prevent from displaying these units.
253+
ctx.Data["RepoHasContentsWithoutBranch"] = true
253254
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
254255
} else {
255256
// the repo is actually not empty and has branches, need to update the database later

templates/repo/empty.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
{{if .Repository.IsBroken}}
1919
<div class="ui segment center">{{ctx.Locale.Tr "repo.broken_message"}}</div>
20-
{{else if .Repository.IsEmpty}}
20+
{{else if .RepoHasContentsWithoutBranch}}
2121
<div class="ui segment center">{{ctx.Locale.Tr "repo.no_branch"}}</div>
2222
{{else if .CanWriteCode}}
2323
<h4 class="ui top attached header">{{ctx.Locale.Tr "repo.quick_guide"}}</h4>

tests/integration/empty_repo_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ func TestEmptyRepoAddFile(t *testing.T) {
5858
defer tests.PrepareTestEnv(t)()
5959

6060
session := loginUser(t, "user30")
61-
req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
61+
req := NewRequest(t, "GET", "/user30/empty")
6262
resp := session.MakeRequest(t, req, http.StatusOK)
63+
assert.Contains(t, resp.Body.String(), "empty-repo-guide")
64+
65+
req = NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
66+
resp = session.MakeRequest(t, req, http.StatusOK)
6367
doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`)
6468
assert.Empty(t, doc.AttrOr("checked", "_no_"))
6569
req = NewRequestWithValues(t, "POST", "/user30/empty/_new/"+setting.Repository.DefaultBranch, map[string]string{

0 commit comments

Comments
 (0)