Browse Source

repo: allow issues and wiki for bare repository (#4104)

pull/4301/head
Unknwon 8 years ago
parent
commit
171f97868d
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 24
      cmd/web.go
  2. 2
      conf/locale/locale_en-US.ini
  3. 2
      gogs.go
  4. 2
      models/repo.go
  5. 4
      modules/bindata/bindata.go
  6. 19
      modules/context/repo.go
  7. 9
      routers/repo/view.go
  8. 2
      templates/.VERSION
  9. 7
      templates/repo/bare.tmpl
  10. 2
      templates/repo/header.tmpl

24
cmd/web.go

@ -529,7 +529,7 @@ func runWeb(ctx *cli.Context) error {
m.Post("/delete", repo.DeleteRelease)
m.Get("/edit/*", repo.EditRelease)
m.Post("/edit/*", bindIgnErr(form.EditRelease{}), repo.EditReleasePost)
}, reqRepoWriter, func(ctx *context.Context) {
}, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true
})
@ -560,17 +560,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.CanEnableEditor() {
ctx.NotFound()
return
}
})
}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare)
}, reqSignIn, context.RepoAssignment())
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 {
m.Get("", repo.Branches)
m.Get("/all", repo.AllBranches)
m.Post("/delete/*", reqSignIn, reqRepoWriter, repo.DeleteBranchPost)
}, func(ctx *context.Context) {
}, repo.MustBeNotBare, func(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true
})
@ -598,7 +598,7 @@ func runWeb(ctx *cli.Context) error {
}, reqSignIn, reqRepoWriter)
}, repo.MustEnableWiki, context.RepoRef())
m.Get("/archive/*", repo.Download)
m.Get("/archive/*", repo.MustBeNotBare, repo.Download)
m.Group("/pulls/:index", func() {
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
@ -612,18 +612,18 @@ func runWeb(ctx *cli.Context) error {
m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.Diff)
m.Get("/forks", repo.Forks)
}, context.RepoRef())
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff)
}, repo.MustBeNotBare, context.RepoRef())
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})", context.RepoRef(), repo.CompareDiff)
}, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare)
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.MustBeNotBare, context.RepoRef(), repo.CompareDiff)
}, ignSignIn, context.RepoAssignment())
m.Group("/:username/:reponame", func() {
m.Get("/stars", repo.Stars)
m.Get("/watchers", repo.Watchers)
}, ignSignIn, context.RepoAssignment(), context.RepoRef())
m.Group("/:username", func() {
m.Get("/:reponame", ignSignIn, context.RepoAssignment(true), context.RepoRef(), repo.Home)
m.Get("/:reponame", ignSignIn, context.RepoAssignment(), context.RepoRef(), repo.Home)
m.Group("/:reponame", func() {
m.Head("/tasks/trigger", repo.TriggerTask)
@ -632,7 +632,7 @@ func runWeb(ctx *cli.Context) error {
// Duplicated routes to enable different ways of accessing same set of URLs,
// e.g. with or without ".git" suffix.
m.Group("/:reponame([\\d\\w-_\\.]+\\.git$)", func() {
m.Get("", ignSignIn, context.RepoAssignment(true), context.RepoRef(), repo.Home)
m.Get("", ignSignIn, context.RepoAssignment(), context.RepoRef(), repo.Home)
m.Route("/*", "GET,POST", ignSignInAndCsrf, repo.HTTPContexter(), repo.HTTP)
})
m.Route("/:reponame/*", "GET,POST", ignSignInAndCsrf, repo.HTTPContexter(), repo.HTTP)

2
conf/locale/locale_en-US.ini

@ -414,7 +414,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.
files = Files
branch = Branch

2
gogs.go

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
const APP_VER = "0.10.20.0316"
const APP_VER = "0.10.21.0316"
func init() {
setting.AppVer = APP_VER

2
models/repo.go

@ -452,7 +452,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
}
// AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled.

4
modules/bindata/bindata.go

File diff suppressed because one or more lines are too long

19
modules/context/repo.go

@ -11,7 +11,6 @@ import (
"strings"
"github.com/Unknwon/com"
log "gopkg.in/clog.v1"
"gopkg.in/editorconfig/editorconfig-core-go.v1"
"gopkg.in/macaron.v1"
@ -143,15 +142,8 @@ func earlyResponseForGoGetMeta(ctx *Context) {
})))
}
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
@ -282,15 +274,6 @@ func RepoAssignment(args ...bool) macaron.Handler {
// repo is bare and display enable
if ctx.Repo.Repository.IsBare {
log.Trace("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")
}
return
}

9
routers/repo/view.go

@ -27,6 +27,7 @@ import (
)
const (
BARE base.TplName = "repo/bare"
HOME base.TplName = "repo/home"
WATCHERS base.TplName = "repo/watchers"
FORKS base.TplName = "repo/forks"
@ -223,6 +224,13 @@ func setEditorconfigIfExists(ctx *context.Context) {
}
func Home(ctx *context.Context) {
ctx.Data["PageIsViewCode"] = true
if ctx.Repo.Repository.IsBare {
ctx.HTML(200, BARE)
return
}
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
if len(ctx.Repo.Repository.Description) > 0 {
title += ": " + ctx.Repo.Repository.Description
@ -231,7 +239,6 @@ func Home(ctx *context.Context) {
if ctx.Repo.BranchName != ctx.Repo.Repository.DefaultBranch {
ctx.Data["Title"] = title + " @ " + ctx.Repo.BranchName
}
ctx.Data["PageIsViewCode"] = true
ctx.Data["RequireHighlightJS"] = true
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName

2
templates/.VERSION

@ -1 +1 @@
0.10.20.0316
0.10.21.0316

7
templates/repo/bare.tmpl

@ -8,9 +8,6 @@
{{if .IsRepositoryAdmin}}
<h4 class="ui top attached header">
{{.i18n.Tr "repo.quick_guide"}}
<div class="ui right">
<a class="ui black tiny button" href="{{.RepoLink}}/settings">{{.i18n.Tr "repo.settings"}}</a>
</div>
</h4>
<div class="ui attached guide table segment">
<div class="item">
@ -54,6 +51,10 @@ git push -u origin master</code></pre>
git push -u origin master</code></pre>
</div>
</div>
{{else}}
<div class="ui segment center">
{{.i18n.Tr "repo.bare_message"}}
</div>
{{end}}
</div>
</div>

2
templates/repo/header.tmpl

@ -46,7 +46,7 @@
</div><!-- end grid -->
</div><!-- end container -->
{{end}}
{{if not (or .IsBareRepo .IsDiffCompare)}}
{{if not .IsDiffCompare}}
<div class="ui tabs container">
<div class="ui tabular menu navbar">
<a class="{{if .PageIsViewCode}}active{{end}} item" href="{{.RepoLink}}">

Loading…
Cancel
Save