Skip to content

Commit b2b9bda

Browse files
jonasfranzlunny
authored andcommitted
Fix #8582 by handling empty repos (#8587)
* Fix #8582 by handling empty repos Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix tests Signed-off-by: Jonas Franz <info@jonasfranz.software>
1 parent 5a62ae5 commit b2b9bda

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-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

+16
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,19 @@ 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.LoadUser(t, ctx, 2)
200+
test.LoadGitRepo(t, ctx)
201+
repo := ctx.Repo.Repository
202+
203+
t.Run("empty repo", func(t *testing.T) {
204+
contents, err := GetContentsOrList(repo, "", "")
205+
assert.NoError(t, err)
206+
assert.Empty(t, contents)
207+
})
208+
}

0 commit comments

Comments
 (0)