forked from Shiloh/githaven
* Fix #8582 by handling empty repos Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix tests Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
parent
5a62ae5cbf
commit
b2b9bdaf26
@ -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
|
// 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
|
// 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) {
|
func GetContentsOrList(repo *models.Repository, treePath, ref string) (interface{}, error) {
|
||||||
|
if repo.IsEmpty {
|
||||||
|
return make([]interface{}, 0), nil
|
||||||
|
}
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
ref = repo.DefaultBranch
|
ref = repo.DefaultBranch
|
||||||
}
|
}
|
||||||
|
@ -190,3 +190,19 @@ func TestGetContentsOrListErrors(t *testing.T) {
|
|||||||
assert.Nil(t, fileContentResponse)
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user