Skip to content

Commit 3cb9364

Browse files
committed
Fix #8582 by handling empty repos
Signed-off-by: Jonas Franz <info@jonasfranz.software>
1 parent 280f4be commit 3cb9364

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

modules/repofiles/content.go

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func (ct *ContentType) String() string {
3838
// GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree
3939
// directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag
4040
func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
41+
if repo.IsEmpty {
42+
return make([]interface{}, 0), nil
43+
}
4144
if ref == "" {
4245
ref = repo.DefaultBranch
4346
}

modules/repofiles/content_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,20 @@ func TestGetContentsOrListErrors(t *testing.T) {
190190
assert.Nil(t, fileContentResponse)
191191
})
192192
}
193+
194+
func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
195+
models.PrepareTestEnv(t)
196+
ctx := test.MockContext(t, "user2/repo15")
197+
ctx.SetParams(":id", "15")
198+
test.LoadRepo(t, ctx, 15)
199+
test.LoadRepoCommit(t, ctx)
200+
test.LoadUser(t, ctx, 2)
201+
test.LoadGitRepo(t, ctx)
202+
repo := ctx.Repo.Repository
203+
204+
t.Run("empty repo", func(t *testing.T) {
205+
contents, err := GetContentsOrList(repo, "", "")
206+
assert.NoError(t, err)
207+
assert.Empty(t, contents)
208+
})
209+
}

0 commit comments

Comments
 (0)