Browse Source

feat: Only use issue and wiki on repo. (#1297)

Bo-Yi Wu 3 years ago
parent
commit
1c3bd436cc

+ 12 - 12
cmd/web.go

@@ -448,7 +448,7 @@ func runWeb(ctx *cli.Context) error {
448 448
 				m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost)
449 449
 				m.Post("/can_push", repo.ChangeProtectedBranch)
450 450
 				m.Post("/delete", repo.DeleteProtectedBranch)
451
-			})
451
+			}, repo.MustBeNotBare)
452 452
 
453 453
 			m.Group("/hooks", func() {
454 454
 				m.Get("", repo.Webhooks)
@@ -520,11 +520,11 @@ func runWeb(ctx *cli.Context) error {
520 520
 			m.Get("/new", repo.NewRelease)
521 521
 			m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
522 522
 			m.Post("/delete", repo.DeleteRelease)
523
-		}, reqRepoWriter, context.RepoRef())
523
+		}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef())
524 524
 		m.Group("/releases", func() {
525 525
 			m.Get("/edit/*", repo.EditRelease)
526 526
 			m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
527
-		}, reqRepoWriter, func(ctx *context.Context) {
527
+		}, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) {
528 528
 			var err error
529 529
 			ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
530 530
 			if err != nil {
@@ -563,17 +563,17 @@ func runWeb(ctx *cli.Context) error {
563 563
 					return
564 564
 				}
565 565
 			})
566
-		}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
566
+		}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
567 567
 			if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
568 568
 				ctx.Handle(404, "", nil)
569 569
 				return
570 570
 			}
571 571
 		})
572
-	}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes())
572
+	}, reqSignIn, context.RepoAssignment(), context.UnitTypes())
573 573
 
574 574
 	m.Group("/:username/:reponame", func() {
575 575
 		m.Group("", func() {
576
-			m.Get("/releases", repo.Releases)
576
+			m.Get("/releases", repo.MustBeNotBare, repo.Releases)
577 577
 			m.Get("/^:type(issues|pulls)$", repo.RetrieveLabels, repo.Issues)
578 578
 			m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue)
579 579
 			m.Get("/labels/", repo.RetrieveLabels, repo.Labels)
@@ -581,7 +581,7 @@ func runWeb(ctx *cli.Context) error {
581 581
 		}, context.RepoRef())
582 582
 
583 583
 		// 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)
585 585
 
586 586
 		m.Group("/wiki", func() {
587 587
 			m.Get("/?:page", repo.Wiki)
@@ -601,7 +601,7 @@ func runWeb(ctx *cli.Context) error {
601 601
 			m.Get("/*", repo.WikiRaw)
602 602
 		}, repo.MustEnableWiki)
603 603
 
604
-		m.Get("/archive/*", repo.Download)
604
+		m.Get("/archive/*", repo.MustBeNotBare, repo.Download)
605 605
 
606 606
 		m.Group("/pulls/:index", func() {
607 607
 			m.Get("/commits", context.RepoRef(), repo.ViewPullCommits)
@@ -617,10 +617,10 @@ func runWeb(ctx *cli.Context) error {
617 617
 			m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
618 618
 			m.Get("/forks", repo.Forks)
619 619
 		}, 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)
621 621
 
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())
624 624
 	m.Group("/:username/:reponame", func() {
625 625
 		m.Get("/stars", repo.Stars)
626 626
 		m.Get("/watchers", repo.Watchers)
@@ -630,7 +630,7 @@ func runWeb(ctx *cli.Context) error {
630 630
 		m.Group("/:reponame", func() {
631 631
 			m.Get("", repo.SetEditorconfigIfExists, repo.Home)
632 632
 			m.Get("\\.git$", repo.SetEditorconfigIfExists, repo.Home)
633
-		}, ignSignIn, context.RepoAssignment(true), context.RepoRef(), context.UnitTypes())
633
+		}, ignSignIn, context.RepoAssignment(), context.RepoRef(), context.UnitTypes())
634 634
 
635 635
 		m.Group("/:reponame", func() {
636 636
 			m.Group("/info/lfs", func() {

+ 1 - 1
models/repo.go

@@ -553,7 +553,7 @@ func (repo *Repository) CanBeForked() bool {
553 553
 
554 554
 // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
555 555
 func (repo *Repository) CanEnablePulls() bool {
556
-	return !repo.IsMirror
556
+	return !repo.IsMirror && !repo.IsBare
557 557
 }
558 558
 
559 559
 // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.

+ 2 - 18
modules/context/repo.go

@@ -12,7 +12,6 @@ import (
12 12
 
13 13
 	"code.gitea.io/git"
14 14
 	"code.gitea.io/gitea/models"
15
-	"code.gitea.io/gitea/modules/log"
16 15
 	"code.gitea.io/gitea/modules/setting"
17 16
 	"github.com/Unknwon/com"
18 17
 	editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1"
@@ -154,16 +153,9 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
154 153
 }
155 154
 
156 155
 // RepoAssignment returns a macaron to handle repository assignment
157
-func RepoAssignment(args ...bool) macaron.Handler {
156
+func RepoAssignment() macaron.Handler {
158 157
 	return func(ctx *Context) {
159 158
 		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
-
166
-		var (
167 159
 			owner *models.User
168 160
 			err   error
169 161
 		)
@@ -294,15 +286,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
294 286
 
295 287
 		// repo is bare and display enable
296 288
 		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
306 290
 			return
307 291
 		}
308 292
 

+ 1 - 1
options/locale/locale_en-US.ini

@@ -479,7 +479,7 @@ quick_guide = Quick Guide
479 479
 clone_this_repo = Clone this repository
480 480
 create_new_repo_command = Create a new repository on the command line
481 481
 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.
483 483
 
484 484
 code = Code
485 485
 branch = Branch

+ 8 - 1
routers/repo/view.go

@@ -28,6 +28,7 @@ import (
28 28
 )
29 29
 
30 30
 const (
31
+	tplRepoBARE base.TplName = "repo/bare"
31 32
 	tplRepoHome base.TplName = "repo/home"
32 33
 	tplWatchers base.TplName = "repo/watchers"
33 34
 	tplForks    base.TplName = "repo/forks"
@@ -243,12 +244,18 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
243 244
 
244 245
 // Home render repository home page
245 246
 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
+
246 254
 	title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name
247 255
 	if len(ctx.Repo.Repository.Description) > 0 {
248 256
 		title += ": " + ctx.Repo.Repository.Description
249 257
 	}
250 258
 	ctx.Data["Title"] = title
251
-	ctx.Data["PageIsViewCode"] = true
252 259
 	ctx.Data["RequireHighlightJS"] = true
253 260
 
254 261
 	branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName

+ 4 - 3
templates/repo/bare.tmpl

@@ -8,9 +8,6 @@
8 8
 				{{if .IsRepositoryAdmin}}
9 9
 					<h4 class="ui top attached header">
10 10
 						{{.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>
14 11
 					</h4>
15 12
 					<div class="ui attached guide table segment">
16 13
 						<div class="item">
@@ -58,6 +55,10 @@ git push -u origin master</code></pre>
58 55
 git push -u origin master</code></pre>
59 56
 							</div>
60 57
 						</div>
58
+					{{else}}
59
+						<div class="ui segment center">
60
+							{{.i18n.Tr "repo.bare_message"}}
61
+						</div>
61 62
 					{{end}}
62 63
 				</div>
63 64
 			</div>

+ 4 - 4
templates/repo/header.tmpl

@@ -46,7 +46,7 @@
46 46
 		</div><!-- end grid -->
47 47
 	</div><!-- end container -->
48 48
 {{end}}
49
-{{if not (or .IsBareRepo .IsDiffCompare)}}
49
+{{if not .IsDiffCompare}}
50 50
 	<div class="ui tabs container">
51 51
 		<div class="ui tabular stackable menu navbar">
52 52
 			{{if .Repository.EnableUnit $.UnitTypeCode}}
@@ -66,20 +66,20 @@
66 66
 					<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span>
67 67
 				</a>
68 68
 			{{end}}
69
-			
69
+
70 70
 			{{if .Repository.AllowsPulls}}
71 71
 				<a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls">
72 72
 					<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>
73 73
 				</a>
74 74
 			{{end}}
75 75
 
76
-			{{if .Repository.EnableUnit $.UnitTypeCommits}}
76
+			{{if and (.Repository.EnableUnit $.UnitTypeCommits) (not .IsBareRepo)}}
77 77
 			<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
78 78
 				<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
79 79
 			</a>
80 80
 			{{end}}
81 81
 
82
-			{{if .Repository.EnableUnit $.UnitTypeReleases}}
82
+			{{if and (.Repository.EnableUnit $.UnitTypeReleases) (not .IsBareRepo) }}
83 83
 			<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
84 84
 				<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>
85 85
 			</a>