From 1c3bd436ccbe3852541dc7162df41632658769db Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 18 Mar 2017 05:59:07 -0500 Subject: [PATCH] feat: Only use issue and wiki on repo. (#1297) --- cmd/web.go | 24 ++++++++++++------------ models/repo.go | 2 +- modules/context/repo.go | 20 ++------------------ options/locale/locale_en-US.ini | 2 +- routers/repo/view.go | 9 ++++++++- templates/repo/bare.tmpl | 7 ++++--- templates/repo/header.tmpl | 8 ++++---- 7 files changed, 32 insertions(+), 40 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 17674b3069..d50ee62a76 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -448,7 +448,7 @@ func runWeb(ctx *cli.Context) error { m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost) m.Post("/can_push", repo.ChangeProtectedBranch) m.Post("/delete", repo.DeleteProtectedBranch) - }) + }, repo.MustBeNotBare) m.Group("/hooks", func() { m.Get("", repo.Webhooks) @@ -520,11 +520,11 @@ func runWeb(ctx *cli.Context) error { m.Get("/new", repo.NewRelease) m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) m.Post("/delete", repo.DeleteRelease) - }, reqRepoWriter, context.RepoRef()) + }, repo.MustBeNotBare, reqRepoWriter, context.RepoRef()) m.Group("/releases", func() { m.Get("/edit/*", repo.EditRelease) m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) - }, reqRepoWriter, func(ctx *context.Context) { + }, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) { var err error ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) if err != nil { @@ -563,17 +563,17 @@ func runWeb(ctx *cli.Context) error { return } }) - }, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) { + }, repo.MustBeNotBare, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) { if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit { ctx.Handle(404, "", nil) return } }) - }, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes()) + }, reqSignIn, context.RepoAssignment(), context.UnitTypes()) m.Group("/:username/:reponame", func() { m.Group("", func() { - m.Get("/releases", repo.Releases) + m.Get("/releases", repo.MustBeNotBare, repo.Releases) m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues) m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) m.Get("/labels/", repo.RetrieveLabels, repo.Labels) @@ -581,7 +581,7 @@ func runWeb(ctx *cli.Context) error { }, context.RepoRef()) // m.Get("/branches", repo.Branches) - m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.DeleteBranchPost) + m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.MustBeNotBare, repo.DeleteBranchPost) m.Group("/wiki", func() { m.Get("/?:page", repo.Wiki) @@ -601,7 +601,7 @@ func runWeb(ctx *cli.Context) error { m.Get("/*", repo.WikiRaw) }, repo.MustEnableWiki) - m.Get("/archive/*", repo.Download) + m.Get("/archive/*", repo.MustBeNotBare, repo.Download) m.Group("/pulls/:index", func() { m.Get("/commits", context.RepoRef(), repo.ViewPullCommits) @@ -617,10 +617,10 @@ func runWeb(ctx *cli.Context) error { m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff) m.Get("/forks", repo.Forks) }, context.RepoRef()) - m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff) + m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.MustBeNotBare, repo.RawDiff) - m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff) - }, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes()) + m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.MustBeNotBare, repo.CompareDiff) + }, ignSignIn, context.RepoAssignment(), context.UnitTypes()) m.Group("/:username/:reponame", func() { m.Get("/stars", repo.Stars) m.Get("/watchers", repo.Watchers) @@ -630,7 +630,7 @@ func runWeb(ctx *cli.Context) error { m.Group("/:reponame", func() { m.Get("", repo.SetEditorconfigIfExists, repo.Home) m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home) - }, ignSignIn, context.RepoAssignment(true), context.RepoRef(), context.UnitTypes()) + }, ignSignIn, context.RepoAssignment(), context.RepoRef(), context.UnitTypes()) m.Group("/:reponame", func() { m.Group("/info/lfs", func() { diff --git a/models/repo.go b/models/repo.go index eac0f015f0..54be49d902 100644 --- a/models/repo.go +++ b/models/repo.go @@ -553,7 +553,7 @@ func (repo *Repository) CanBeForked() bool { // CanEnablePulls returns true if repository meets the requirements of accepting pulls. func (repo *Repository) CanEnablePulls() bool { - return !repo.IsMirror + return !repo.IsMirror && !repo.IsBare } // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled. diff --git a/modules/context/repo.go b/modules/context/repo.go index 895640a823..aae76185e2 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -12,7 +12,6 @@ import ( "code.gitea.io/git" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "github.com/Unknwon/com" editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1" @@ -154,15 +153,8 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) { } // RepoAssignment returns a macaron to handle repository assignment -func RepoAssignment(args ...bool) macaron.Handler { +func RepoAssignment() macaron.Handler { return func(ctx *Context) { - var ( - displayBare bool // To display bare page if it is a bare repo. - ) - if len(args) >= 1 { - displayBare = args[0] - } - var ( owner *models.User err error @@ -294,15 +286,7 @@ func RepoAssignment(args ...bool) macaron.Handler { // repo is bare and display enable if ctx.Repo.Repository.IsBare { - log.Debug("Bare repository: %s", ctx.Repo.RepoLink) - // NOTE: to prevent templating error - ctx.Data["BranchName"] = "" - if displayBare { - if !ctx.Repo.IsAdmin() { - ctx.Flash.Info(ctx.Tr("repo.repo_is_empty"), true) - } - ctx.HTML(200, "repo/bare") - } + ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch return } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index cf322c7f33..98dfaab5d4 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -479,7 +479,7 @@ quick_guide = Quick Guide clone_this_repo = Clone this repository create_new_repo_command = Create a new repository on the command line push_exist_repo = Push an existing repository from the command line -repo_is_empty = This repository is empty, please come back later! +bare_message = This repository does not have any content yet. code = Code branch = Branch diff --git a/routers/repo/view.go b/routers/repo/view.go index 5f9d78a52f..51443a9452 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -28,6 +28,7 @@ import ( ) const ( + tplRepoBARE base.TplName = "repo/bare" tplRepoHome base.TplName = "repo/home" tplWatchers base.TplName = "repo/watchers" tplForks base.TplName = "repo/forks" @@ -243,12 +244,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st // Home render repository home page func Home(ctx *context.Context) { + ctx.Data["PageIsViewCode"] = true + + if ctx.Repo.Repository.IsBare { + ctx.HTML(200, tplRepoBARE) + return + } + title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name if len(ctx.Repo.Repository.Description) > 0 { title += ": " + ctx.Repo.Repository.Description } ctx.Data["Title"] = title - ctx.Data["PageIsViewCode"] = true ctx.Data["RequireHighlightJS"] = true branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName diff --git a/templates/repo/bare.tmpl b/templates/repo/bare.tmpl index af45e672c5..b72738fe34 100644 --- a/templates/repo/bare.tmpl +++ b/templates/repo/bare.tmpl @@ -8,9 +8,6 @@ {{if .IsRepositoryAdmin}}

{{.i18n.Tr "repo.quick_guide"}} -

@@ -58,6 +55,10 @@ git push -u origin master git push -u origin master
+ {{else}} +
+ {{.i18n.Tr "repo.bare_message"}} +
{{end}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 16a2be4aa1..2317b5ba86 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -46,7 +46,7 @@ {{end}} -{{if not (or .IsBareRepo .IsDiffCompare)}} +{{if not .IsDiffCompare}}