diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go index 1d8e3b3b1..ef4bab5c1 100644 --- a/routers/api/v1/repo/wiki.go +++ b/routers/api/v1/repo/wiki.go @@ -326,7 +326,12 @@ func ListWikiPages(ctx *context.APIContext) { continue } if entry.IsRegular() { - c, err := wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name())) + var commit *git.Commit + if filePath == "" { + commit, err = wikiRepo.GetCommitByPath(entry.Name()) + } else { + commit, err = wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name())) + } if err != nil { ctx.Error(http.StatusInternalServerError, "GetCommit", err) return @@ -339,15 +344,20 @@ func ListWikiPages(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err) return } - lists = append(lists, convert.RegularToWikiPageMetaData(wikiName, c, ctx.Repo.Repository)) + lists = append(lists, convert.RegularToWikiPageMetaData(wikiName, commit, ctx.Repo.Repository)) } if entry.IsDir() { - c, err := wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name())) + var commit *git.Commit + if filePath == "" { + commit, err = wikiRepo.GetCommitByPath(entry.Name()) + } else { + commit, err = wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name())) + } if err != nil { ctx.Error(http.StatusInternalServerError, "GetCommit", err) return } - lists = append(lists, convert.DirToWikiPageMetaData(entry.Name(), c, ctx.Repo.Repository)) + lists = append(lists, convert.DirToWikiPageMetaData(entry.Name(), commit, ctx.Repo.Repository)) } }