Skip to content

Commit bd8fe49

Browse files
authored
fix wiki bugs (#1294)
1 parent dbabc35 commit bd8fe49

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

models/wiki.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ func (repo *Repository) LocalWikiPath() string {
8484
func (repo *Repository) UpdateLocalWiki() error {
8585
// Don't pass branch name here because it fails to clone and
8686
// checkout to a specific branch when wiki is an empty repository.
87-
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), "")
87+
var branch = ""
88+
if com.IsExist(repo.LocalWikiPath()) {
89+
branch = "master"
90+
}
91+
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), branch)
8892
}
8993

9094
func discardLocalWikiChanges(localPath string) error {

routers/repo/wiki.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, err
177177
// ctx.Handle(500, "OpenRepository", err)
178178
return nil, nil, err
179179
}
180+
if !wikiRepo.IsBranchExist("master") {
181+
return wikiRepo, nil, nil
182+
}
183+
180184
commit, err := wikiRepo.GetBranchCommit("master")
181185
if err != nil {
182186
ctx.Handle(500, "GetBranchCommit", err)
@@ -190,6 +194,9 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
190194
if err != nil {
191195
return nil, nil
192196
}
197+
if commit == nil {
198+
return wikiRepo, nil
199+
}
193200

194201
// Get page list.
195202
if isViewPage {
@@ -210,7 +217,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
210217
}
211218
pages = append(pages, PageMeta{
212219
Name: models.ToWikiPageName(name),
213-
URL: models.ToWikiPageURL(name),
220+
URL: name,
214221
})
215222
}
216223
}
@@ -308,6 +315,11 @@ func Wiki(ctx *context.Context) {
308315
if ctx.Written() {
309316
return
310317
}
318+
if entry == nil {
319+
ctx.Data["Title"] = ctx.Tr("repo.wiki")
320+
ctx.HTML(200, tplWikiStart)
321+
return
322+
}
311323

312324
ename := entry.Name()
313325
if !markdown.IsMarkdownFile(ename) {
@@ -362,7 +374,7 @@ func WikiPages(ctx *context.Context) {
362374
}
363375
pages = append(pages, PageMeta{
364376
Name: models.ToWikiPageName(name),
365-
URL: models.ToWikiPageURL(name),
377+
URL: name,
366378
Updated: c.Author.When,
367379
})
368380
}
@@ -480,7 +492,7 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
480492
return
481493
}
482494

483-
oldWikiPath := ctx.Params(":page")
495+
oldWikiPath := models.ToWikiPageURL(ctx.Params(":page"))
484496
newWikiPath := models.ToWikiPageURL(form.Title)
485497

486498
if err := ctx.Repo.Repository.EditWikiPage(ctx.User, oldWikiPath, newWikiPath, form.Content, form.Message); err != nil {
@@ -493,7 +505,7 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
493505

494506
// DeleteWikiPagePost delete wiki page
495507
func DeleteWikiPagePost(ctx *context.Context) {
496-
pageURL := ctx.Params(":page")
508+
pageURL := models.ToWikiPageURL(ctx.Params(":page"))
497509
if len(pageURL) == 0 {
498510
pageURL = "Home"
499511
}

0 commit comments

Comments
 (0)