Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wiki bugs (#1294) #1338

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion models/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ func (repo *Repository) LocalWikiPath() string {
func (repo *Repository) UpdateLocalWiki() error {
// Don't pass branch name here because it fails to clone and
// checkout to a specific branch when wiki is an empty repository.
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), "")
var branch = ""
if com.IsExist(repo.LocalWikiPath()) {
branch = "master"
}
return UpdateLocalCopyBranch(repo.WikiPath(), repo.LocalWikiPath(), branch)
}

func discardLocalWikiChanges(localPath string) error {
Expand Down
20 changes: 16 additions & 4 deletions routers/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, err
// ctx.Handle(500, "OpenRepository", err)
return nil, nil, err
}
if !wikiRepo.IsBranchExist("master") {
return wikiRepo, nil, nil
}

commit, err := wikiRepo.GetBranchCommit("master")
if err != nil {
ctx.Handle(500, "GetBranchCommit", err)
Expand All @@ -190,6 +194,9 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
if err != nil {
return nil, nil
}
if commit == nil {
return wikiRepo, nil
}

// Get page list.
if isViewPage {
Expand All @@ -210,7 +217,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, *gi
}
pages = append(pages, PageMeta{
Name: models.ToWikiPageName(name),
URL: models.ToWikiPageURL(name),
URL: name,
})
}
}
Expand Down Expand Up @@ -308,6 +315,11 @@ func Wiki(ctx *context.Context) {
if ctx.Written() {
return
}
if entry == nil {
ctx.Data["Title"] = ctx.Tr("repo.wiki")
ctx.HTML(200, tplWikiStart)
return
}

ename := entry.Name()
if !markdown.IsMarkdownFile(ename) {
Expand Down Expand Up @@ -362,7 +374,7 @@ func WikiPages(ctx *context.Context) {
}
pages = append(pages, PageMeta{
Name: models.ToWikiPageName(name),
URL: models.ToWikiPageURL(name),
URL: name,
Updated: c.Author.When,
})
}
Expand Down Expand Up @@ -480,7 +492,7 @@ func EditWikiPost(ctx *context.Context, form auth.NewWikiForm) {
return
}

oldWikiPath := ctx.Params(":page")
oldWikiPath := models.ToWikiPageURL(ctx.Params(":page"))
newWikiPath := models.ToWikiPageURL(form.Title)

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

// DeleteWikiPagePost delete wiki page
func DeleteWikiPagePost(ctx *context.Context) {
pageURL := ctx.Params(":page")
pageURL := models.ToWikiPageURL(ctx.Params(":page"))
if len(pageURL) == 0 {
pageURL = "Home"
}
Expand Down