Skip to content

Commit 1c3bd43

Browse files
appleboylunny
authored andcommitted
feat: Only use issue and wiki on repo. (#1297)
1 parent 5ecb369 commit 1c3bd43

File tree

7 files changed

+32
-40
lines changed

7 files changed

+32
-40
lines changed

cmd/web.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func runWeb(ctx *cli.Context) error {
448448
m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost)
449449
m.Post("/can_push", repo.ChangeProtectedBranch)
450450
m.Post("/delete", repo.DeleteProtectedBranch)
451-
})
451+
}, repo.MustBeNotBare)
452452

453453
m.Group("/hooks", func() {
454454
m.Get("", repo.Webhooks)
@@ -520,11 +520,11 @@ func runWeb(ctx *cli.Context) error {
520520
m.Get("/new", repo.NewRelease)
521521
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
522522
m.Post("/delete", repo.DeleteRelease)
523-
}, reqRepoWriter, context.RepoRef())
523+
}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef())
524524
m.Group("/releases", func() {
525525
m.Get("/edit/*", repo.EditRelease)
526526
m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
527-
}, reqRepoWriter, func(ctx *context.Context) {
527+
}, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
528528
var err error
529529
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
530530
if err != nil {
@@ -563,25 +563,25 @@ func runWeb(ctx *cli.Context) error {
563563
return
564564
}
565565
})
566-
}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
566+
}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
567567
if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
568568
ctx.Handle(404, "", nil)
569569
return
570570
}
571571
})
572-
}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes())
572+
}, reqSignIn, context.RepoAssignment(), context.UnitTypes())
573573

574574
m.Group("/:username/:reponame", func() {
575575
m.Group("", func() {
576-
m.Get("/releases", repo.Releases)
576+
m.Get("/releases", repo.MustBeNotBare, repo.Releases)
577577
m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
578578
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
579579
m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
580580
m.Get("/milestones", repo.Milestones)
581581
}, context.RepoRef())
582582

583583
// m.Get("/branches", repo.Branches)
584-
m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.DeleteBranchPost)
584+
m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.MustBeNotBare, repo.DeleteBranchPost)
585585

586586
m.Group("/wiki", func() {
587587
m.Get("/?:page", repo.Wiki)
@@ -601,7 +601,7 @@ func runWeb(ctx *cli.Context) error {
601601
m.Get("/*", repo.WikiRaw)
602602
}, repo.MustEnableWiki)
603603

604-
m.Get("/archive/*", repo.Download)
604+
m.Get("/archive/*", repo.MustBeNotBare, repo.Download)
605605

606606
m.Group("/pulls/:index", func() {
607607
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
@@ -617,10 +617,10 @@ func runWeb(ctx *cli.Context) error {
617617
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
618618
m.Get("/forks", repo.Forks)
619619
}, context.RepoRef())
620-
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.RawDiff)
620+
m.Get("/commit/:sha([a-f0-9]{7,40})\\.:ext(patch|diff)", repo.MustBeNotBare, repo.RawDiff)
621621

622-
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff)
623-
}, ignSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes())
622+
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.MustBeNotBare, repo.CompareDiff)
623+
}, ignSignIn, context.RepoAssignment(), context.UnitTypes())
624624
m.Group("/:username/:reponame", func() {
625625
m.Get("/stars", repo.Stars)
626626
m.Get("/watchers", repo.Watchers)
@@ -630,7 +630,7 @@ func runWeb(ctx *cli.Context) error {
630630
m.Group("/:reponame", func() {
631631
m.Get("", repo.SetEditorconfigIfExists, repo.Home)
632632
m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home)
633-
}, ignSignIn, context.RepoAssignment(true), context.RepoRef(), context.UnitTypes())
633+
}, ignSignIn, context.RepoAssignment(), context.RepoRef(), context.UnitTypes())
634634

635635
m.Group("/:reponame", func() {
636636
m.Group("/info/lfs", func() {

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func (repo *Repository) CanBeForked() bool {
553553

554554
// CanEnablePulls returns true if repository meets the requirements of accepting pulls.
555555
func (repo *Repository) CanEnablePulls() bool {
556-
return !repo.IsMirror
556+
return !repo.IsMirror && !repo.IsBare
557557
}
558558

559559
// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.

modules/context/repo.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"code.gitea.io/git"
1414
"code.gitea.io/gitea/models"
15-
"code.gitea.io/gitea/modules/log"
1615
"code.gitea.io/gitea/modules/setting"
1716
"github.com/Unknwon/com"
1817
editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1"
@@ -154,15 +153,8 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
154153
}
155154

156155
// RepoAssignment returns a macaron to handle repository assignment
157-
func RepoAssignment(args ...bool) macaron.Handler {
156+
func RepoAssignment() macaron.Handler {
158157
return func(ctx *Context) {
159-
var (
160-
displayBare bool // To display bare page if it is a bare repo.
161-
)
162-
if len(args) >= 1 {
163-
displayBare = args[0]
164-
}
165-
166158
var (
167159
owner *models.User
168160
err error
@@ -294,15 +286,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
294286

295287
// repo is bare and display enable
296288
if ctx.Repo.Repository.IsBare {
297-
log.Debug("Bare repository: %s", ctx.Repo.RepoLink)
298-
// NOTE: to prevent templating error
299-
ctx.Data["BranchName"] = ""
300-
if displayBare {
301-
if !ctx.Repo.IsAdmin() {
302-
ctx.Flash.Info(ctx.Tr("repo.repo_is_empty"), true)
303-
}
304-
ctx.HTML(200, "repo/bare")
305-
}
289+
ctx.Data["BranchName"] = ctx.Repo.Repository.DefaultBranch
306290
return
307291
}
308292

options/locale/locale_en-US.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ quick_guide = Quick Guide
479479
clone_this_repo = Clone this repository
480480
create_new_repo_command = Create a new repository on the command line
481481
push_exist_repo = Push an existing repository from the command line
482-
repo_is_empty = This repository is empty, please come back later!
482+
bare_message = This repository does not have any content yet.
483483
484484
code = Code
485485
branch = Branch

routers/repo/view.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
)
2929

3030
const (
31+
tplRepoBARE base.TplName = "repo/bare"
3132
tplRepoHome base.TplName = "repo/home"
3233
tplWatchers base.TplName = "repo/watchers"
3334
tplForks base.TplName = "repo/forks"
@@ -243,12 +244,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
243244

244245
// Home render repository home page
245246
func Home(ctx *context.Context) {
247+
ctx.Data["PageIsViewCode"] = true
248+
249+
if ctx.Repo.Repository.IsBare {
250+
ctx.HTML(200, tplRepoBARE)
251+
return
252+
}
253+
246254
title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
247255
if len(ctx.Repo.Repository.Description) > 0 {
248256
title += ": " + ctx.Repo.Repository.Description
249257
}
250258
ctx.Data["Title"] = title
251-
ctx.Data["PageIsViewCode"] = true
252259
ctx.Data["RequireHighlightJS"] = true
253260

254261
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName

templates/repo/bare.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
{{if .IsRepositoryAdmin}}
99
<h4 class="ui top attached header">
1010
{{.i18n.Tr "repo.quick_guide"}}
11-
<div class="ui right">
12-
<a class="ui black tiny button" href="{{.RepoLink}}/settings">{{.i18n.Tr "repo.settings"}}</a>
13-
</div>
1411
</h4>
1512
<div class="ui attached guide table segment">
1613
<div class="item">
@@ -58,6 +55,10 @@ git push -u origin master</code></pre>
5855
git push -u origin master</code></pre>
5956
</div>
6057
</div>
58+
{{else}}
59+
<div class="ui segment center">
60+
{{.i18n.Tr "repo.bare_message"}}
61+
</div>
6162
{{end}}
6263
</div>
6364
</div>

templates/repo/header.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</div><!-- end grid -->
4747
</div><!-- end container -->
4848
{{end}}
49-
{{if not (or .IsBareRepo .IsDiffCompare)}}
49+
{{if not .IsDiffCompare}}
5050
<div class="ui tabs container">
5151
<div class="ui tabular stackable menu navbar">
5252
{{if .Repository.EnableUnit $.UnitTypeCode}}
@@ -66,20 +66,20 @@
6666
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span>
6767
</a>
6868
{{end}}
69-
69+
7070
{{if .Repository.AllowsPulls}}
7171
<a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls">
7272
<i class="octicon octicon-git-pull-request"></i> {{.i18n.Tr "repo.pulls"}} <span class="ui {{if not .Repository.NumOpenPulls}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenPulls}}</span>
7373
</a>
7474
{{end}}
7575

76-
{{if .Repository.EnableUnit $.UnitTypeCommits}}
76+
{{if and (.Repository.EnableUnit $.UnitTypeCommits) (not .IsBareRepo)}}
7777
<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
7878
<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
7979
</a>
8080
{{end}}
8181

82-
{{if .Repository.EnableUnit $.UnitTypeReleases}}
82+
{{if and (.Repository.EnableUnit $.UnitTypeReleases) (not .IsBareRepo) }}
8383
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
8484
<i class="octicon octicon-tag"></i> {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumTags}}gray{{else}}blue{{end}} small label">{{.Repository.NumTags}}</span>
8585
</a>

0 commit comments

Comments
 (0)