m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost) | m.Combo("").Get(repo.ProtectedBranch).Post(repo.ProtectedBranchPost) | ||||
m.Post("/can_push", repo.ChangeProtectedBranch) | m.Post("/can_push", repo.ChangeProtectedBranch) | ||||
m.Post("/delete", repo.DeleteProtectedBranch) | m.Post("/delete", repo.DeleteProtectedBranch) | ||||
}) | |||||
}, repo.MustBeNotBare) | |||||
m.Group("/hooks", func() { | m.Group("/hooks", func() { | ||||
m.Get("", repo.Webhooks) | m.Get("", repo.Webhooks) | ||||
m.Get("/new", repo.NewRelease) | m.Get("/new", repo.NewRelease) | ||||
m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) | m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost) | ||||
m.Post("/delete", repo.DeleteRelease) | m.Post("/delete", repo.DeleteRelease) | ||||
}, reqRepoWriter, context.RepoRef()) | |||||
}, repo.MustBeNotBare, reqRepoWriter, context.RepoRef()) | |||||
m.Group("/releases", func() { | m.Group("/releases", func() { | ||||
m.Get("/edit/*", repo.EditRelease) | m.Get("/edit/*", repo.EditRelease) | ||||
m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) | m.Post("/edit/*", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost) | ||||
}, reqRepoWriter, func(ctx *context.Context) { | |||||
}, repo.MustBeNotBare, reqRepoWriter, func(ctx *context.Context) { | |||||
var err error | var err error | ||||
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) | ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch) | ||||
if err != nil { | if err != nil { | ||||
return | 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 { | if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit { | ||||
ctx.Handle(404, "", nil) | ctx.Handle(404, "", nil) | ||||
return | return | ||||
} | } | ||||
}) | }) | ||||
}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare, context.UnitTypes()) | |||||
}, reqSignIn, context.RepoAssignment(), context.UnitTypes()) | |||||
m.Group("/:username/:reponame", func() { | m.Group("/:username/:reponame", func() { | ||||
m.Group("", 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)$", repo.RetrieveLabels, repo.Issues) | ||||
m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) | m.Get("/^:type(issues|pulls)$/:index", repo.ViewIssue) | ||||
m.Get("/labels/", repo.RetrieveLabels, repo.Labels) | m.Get("/labels/", repo.RetrieveLabels, repo.Labels) | ||||
}, context.RepoRef()) | }, context.RepoRef()) | ||||
// m.Get("/branches", repo.Branches) | // 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.Group("/wiki", func() { | ||||
m.Get("/?:page", repo.Wiki) | m.Get("/?:page", repo.Wiki) | ||||
m.Get("/*", repo.WikiRaw) | m.Get("/*", repo.WikiRaw) | ||||
}, repo.MustEnableWiki) | }, repo.MustEnableWiki) | ||||
m.Get("/archive/*", repo.Download) | |||||
m.Get("/archive/*", repo.MustBeNotBare, repo.Download) | |||||
m.Group("/pulls/:index", func() { | m.Group("/pulls/:index", func() { | ||||
m.Get("/commits", context.RepoRef(), repo.ViewPullCommits) | m.Get("/commits", context.RepoRef(), repo.ViewPullCommits) | ||||
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff) | m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff) | ||||
m.Get("/forks", repo.Forks) | m.Get("/forks", repo.Forks) | ||||
}, context.RepoRef()) | }, 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.Group("/:username/:reponame", func() { | ||||
m.Get("/stars", repo.Stars) | m.Get("/stars", repo.Stars) | ||||
m.Get("/watchers", repo.Watchers) | m.Get("/watchers", repo.Watchers) | ||||
m.Group("/:reponame", func() { | m.Group("/:reponame", func() { | ||||
m.Get("", repo.SetEditorconfigIfExists, repo.Home) | m.Get("", repo.SetEditorconfigIfExists, repo.Home) | ||||
m.Get("\\.git$", 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("/:reponame", func() { | ||||
m.Group("/info/lfs", func() { | m.Group("/info/lfs", func() { |
// CanEnablePulls returns true if repository meets the requirements of accepting pulls. | // CanEnablePulls returns true if repository meets the requirements of accepting pulls. | ||||
func (repo *Repository) CanEnablePulls() bool { | 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. | // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled. |
"code.gitea.io/git" | "code.gitea.io/git" | ||||
"code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
"code.gitea.io/gitea/modules/log" | |||||
"code.gitea.io/gitea/modules/setting" | "code.gitea.io/gitea/modules/setting" | ||||
"github.com/Unknwon/com" | "github.com/Unknwon/com" | ||||
editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1" | editorconfig "gopkg.in/editorconfig/editorconfig-core-go.v1" | ||||
} | } | ||||
// RepoAssignment returns a macaron to handle repository assignment | // RepoAssignment returns a macaron to handle repository assignment | ||||
func RepoAssignment(args ...bool) macaron.Handler { | |||||
func RepoAssignment() macaron.Handler { | |||||
return func(ctx *Context) { | 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 ( | var ( | ||||
owner *models.User | owner *models.User | ||||
err error | err error | ||||
// repo is bare and display enable | // repo is bare and display enable | ||||
if ctx.Repo.Repository.IsBare { | 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 | return | ||||
} | } | ||||
clone_this_repo = Clone this repository | clone_this_repo = Clone this repository | ||||
create_new_repo_command = Create a new repository on the command line | create_new_repo_command = Create a new repository on the command line | ||||
push_exist_repo = Push an existing repository from 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 | code = Code | ||||
branch = Branch | branch = Branch |
) | ) | ||||
const ( | const ( | ||||
tplRepoBARE base.TplName = "repo/bare" | |||||
tplRepoHome base.TplName = "repo/home" | tplRepoHome base.TplName = "repo/home" | ||||
tplWatchers base.TplName = "repo/watchers" | tplWatchers base.TplName = "repo/watchers" | ||||
tplForks base.TplName = "repo/forks" | tplForks base.TplName = "repo/forks" | ||||
// Home render repository home page | // Home render repository home page | ||||
func Home(ctx *context.Context) { | 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 | title := ctx.Repo.Repository.Owner.Name + "/" + ctx.Repo.Repository.Name | ||||
if len(ctx.Repo.Repository.Description) > 0 { | if len(ctx.Repo.Repository.Description) > 0 { | ||||
title += ": " + ctx.Repo.Repository.Description | title += ": " + ctx.Repo.Repository.Description | ||||
} | } | ||||
ctx.Data["Title"] = title | ctx.Data["Title"] = title | ||||
ctx.Data["PageIsViewCode"] = true | |||||
ctx.Data["RequireHighlightJS"] = true | ctx.Data["RequireHighlightJS"] = true | ||||
branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName | branchLink := ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName |
{{if .IsRepositoryAdmin}} | {{if .IsRepositoryAdmin}} | ||||
<h4 class="ui top attached header"> | <h4 class="ui top attached header"> | ||||
{{.i18n.Tr "repo.quick_guide"}} | {{.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> | </h4> | ||||
<div class="ui attached guide table segment"> | <div class="ui attached guide table segment"> | ||||
<div class="item"> | <div class="item"> | ||||
git push -u origin master</code></pre> | git push -u origin master</code></pre> | ||||
</div> | </div> | ||||
</div> | </div> | ||||
{{else}} | |||||
<div class="ui segment center"> | |||||
{{.i18n.Tr "repo.bare_message"}} | |||||
</div> | |||||
{{end}} | {{end}} | ||||
</div> | </div> | ||||
</div> | </div> |
</div><!-- end grid --> | </div><!-- end grid --> | ||||
</div><!-- end container --> | </div><!-- end container --> | ||||
{{end}} | {{end}} | ||||
{{if not (or .IsBareRepo .IsDiffCompare)}} | |||||
{{if not .IsDiffCompare}} | |||||
<div class="ui tabs container"> | <div class="ui tabs container"> | ||||
<div class="ui tabular stackable menu navbar"> | <div class="ui tabular stackable menu navbar"> | ||||
{{if .Repository.EnableUnit $.UnitTypeCode}} | {{if .Repository.EnableUnit $.UnitTypeCode}} | ||||
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span> | <i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span> | ||||
</a> | </a> | ||||
{{end}} | {{end}} | ||||
{{if .Repository.AllowsPulls}} | {{if .Repository.AllowsPulls}} | ||||
<a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls"> | <a class="{{if .PageIsPullList}}active{{end}} item" href="{{.RepoLink}}/pulls"> | ||||
<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> | <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> | ||||
</a> | </a> | ||||
{{end}} | {{end}} | ||||
{{if .Repository.EnableUnit $.UnitTypeCommits}} | |||||
{{if and (.Repository.EnableUnit $.UnitTypeCommits) (not .IsBareRepo)}} | |||||
<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}"> | <a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}"> | ||||
<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span> | <i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span> | ||||
</a> | </a> | ||||
{{end}} | {{end}} | ||||
{{if .Repository.EnableUnit $.UnitTypeReleases}} | |||||
{{if and (.Repository.EnableUnit $.UnitTypeReleases) (not .IsBareRepo) }} | |||||
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases"> | <a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases"> | ||||
<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> | <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> | ||||
</a> | </a> |