diff options
author | Jonas Franz <info@jonasfranz.software> | 2019-10-19 17:38:49 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-19 23:38:49 +0800 |
commit | b2b9bdaf2647d33d40ca6bf993c8691121912a4d (patch) | |
tree | d520f8f97da1d9ab0ad82277ccc0398237e40de1 /modules/repofiles | |
parent | 5a62ae5cbf47cf6537f6c95aba4b1d04dea5f5af (diff) | |
download | gitea-b2b9bdaf2647d33d40ca6bf993c8691121912a4d.tar.gz gitea-b2b9bdaf2647d33d40ca6bf993c8691121912a4d.zip |
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>
Diffstat (limited to 'modules/repofiles')
-rw-r--r-- | modules/repofiles/content.go | 3 | ||||
-rw-r--r-- | modules/repofiles/content_test.go | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/modules/repofiles/content.go b/modules/repofiles/content.go index 9637658e78..d7d43ef9d1 100644 --- a/modules/repofiles/content.go +++ b/modules/repofiles/content.go @@ -38,6 +38,9 @@ func (ct *ContentType) String() string { // GetContentsOrList gets the meta data of a file's contents (*ContentsResponse) if treePath not a tree // directory, otherwise a listing of file contents ([]*ContentsResponse). Ref can be a branch, commit or tag func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) { + if repo.IsEmpty { + return make([]interface{}, 0), nil + } if ref == "" { ref = repo.DefaultBranch } diff --git a/modules/repofiles/content_test.go b/modules/repofiles/content_test.go index ef6c5eafc2..cd98c54ea6 100644 --- a/modules/repofiles/content_test.go +++ b/modules/repofiles/content_test.go @@ -190,3 +190,19 @@ func TestGetContentsOrListErrors(t *testing.T) { assert.Nil(t, fileContentResponse) }) } + +func TestGetContentsOrListOfEmptyRepos(t *testing.T) { + models.PrepareTestEnv(t) + ctx := test.MockContext(t, "user2/repo15") + ctx.SetParams(":id", "15") + test.LoadRepo(t, ctx, 15) + test.LoadUser(t, ctx, 2) + test.LoadGitRepo(t, ctx) + repo := ctx.Repo.Repository + + t.Run("empty repo", func(t *testing.T) { + contents, err := GetContentsOrList(repo, "", "") + assert.NoError(t, err) + assert.Empty(t, contents) + }) +} |