From ba37e97a6bb62e206d7352027945f7dcb194c1fa Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 20 Mar 2017 21:36:19 +0800 Subject: [PATCH 1/2] fix wiki bugs (#1294) --- models/wiki.go | 6 +++++- routers/repo/wiki.go | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/models/wiki.go b/models/wiki.go index 690da707c657d..d864505d56c25 100644 --- a/models/wiki.go +++ b/models/wiki.go @@ -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 { diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 2633ae9ceae04..c1c05d305a375 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -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) @@ -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 { @@ -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, }) } } @@ -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) { @@ -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, }) } @@ -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 { @@ -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" } From c6924cba56c35586e6beeb5059f892553d4957db Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 10 Mar 2017 16:58:53 +0800 Subject: [PATCH 2/2] fix migration failed when authorized_keys is not exist --- models/migrations/v21.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/models/migrations/v21.go b/models/migrations/v21.go index f7f01f062b750..e049727cbeebe 100644 --- a/models/migrations/v21.go +++ b/models/migrations/v21.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/setting" + "github.com/Unknwon/com" "github.com/go-xorm/xorm" ) @@ -21,6 +22,10 @@ const ( func useNewPublickeyFormat(x *xorm.Engine) error { fpath := filepath.Join(setting.SSH.RootPath, "authorized_keys") + if !com.IsExist(fpath) { + return nil + } + tmpPath := fpath + ".tmp" f, err := os.OpenFile(tmpPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil {