Skip to content

Commit 0f9ba8b

Browse files
committed
temp fix
1 parent 5191149 commit 0f9ba8b

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

routers/web/repo/view_home.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
241241
showEmpty := true
242242
if ctx.Repo.GitRepo != nil {
243243
reallyEmpty, err := ctx.Repo.GitRepo.IsEmpty()
244+
defaultBranchCommit, _ := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
244245
if err != nil {
245246
showEmpty = true // the repo is broken
246247
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryBroken)
@@ -249,7 +250,7 @@ func handleRepoEmptyOrBroken(ctx *context.Context) {
249250
} else if reallyEmpty {
250251
showEmpty = true // the repo is really empty
251252
updateContextRepoEmptyAndStatus(ctx, true, repo_model.RepositoryReady)
252-
} else if ctx.Repo.Commit == nil {
253+
} else if defaultBranchCommit == nil {
253254
showEmpty = true // it is not really empty, but there is no branch
254255
// at the moment, other repo units like "actions" are not able to handle such case,
255256
// so we just mark the repo as empty to prevent from displaying these units.

routers/web/web.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ func registerRoutes(m *web.Router) {
11531153
// end "/{username}/{reponame}/settings"
11541154

11551155
// user/org home, including rss feeds
1156-
m.Get("/{username}/{reponame}", optSignIn, context.RepoAssignment, context.RepoRef(), repo.SetEditorconfigIfExists, repo.Home)
1156+
m.Get("/{username}/{reponame}", optSignIn, context.RepoAssignment, context.RepoRefByType(git.RefTypeBranch), repo.SetEditorconfigIfExists, repo.Home)
11571157

11581158
m.Post("/{username}/{reponame}/markup", optSignIn, context.RepoAssignment, reqUnitsWithMarkdown, web.Bind(structs.MarkupOption{}), misc.Markup)
11591159

@@ -1333,39 +1333,36 @@ func registerRoutes(m *web.Router) {
13331333
m.Group("/{username}/{reponame}", func() { // repo tags
13341334
m.Group("/tags", func() {
13351335
m.Get("", repo.TagsList)
1336-
m.Get("/list", repo.GetTagList)
13371336
m.Get(".rss", feedEnabled, repo.TagsListFeedRSS)
13381337
m.Get(".atom", feedEnabled, repo.TagsListFeedAtom)
1339-
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
1340-
repo.MustBeNotEmpty, context.RepoRefByType(git.RefTypeTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
1341-
m.Post("/tags/delete", repo.DeleteTag, reqSignIn,
1342-
repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoCodeWriter, context.RepoRef())
1343-
}, optSignIn, context.RepoAssignment, reqUnitCodeReader)
1338+
m.Get("/list", repo.GetTagList)
1339+
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed))
1340+
m.Post("/tags/delete", reqSignIn, reqRepoCodeWriter, context.RepoMustNotBeArchived(), repo.DeleteTag)
1341+
}, optSignIn, context.RepoAssignment, repo.MustBeNotEmpty, reqUnitCodeReader)
13441342
// end "/{username}/{reponame}": repo tags
13451343

13461344
m.Group("/{username}/{reponame}", func() { // repo releases
13471345
m.Group("/releases", func() {
13481346
m.Get("", repo.Releases)
1349-
m.Get("/tag/*", repo.SingleRelease)
1350-
m.Get("/latest", repo.LatestRelease)
13511347
m.Get(".rss", feedEnabled, repo.ReleasesFeedRSS)
13521348
m.Get(".atom", feedEnabled, repo.ReleasesFeedAtom)
1353-
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed),
1354-
repo.MustBeNotEmpty, context.RepoRefByType(git.RefTypeTag, context.RepoRefByTypeOptions{IgnoreNotExistErr: true}))
1355-
m.Get("/releases/attachments/{uuid}", repo.MustBeNotEmpty, repo.GetAttachment)
1356-
m.Get("/releases/download/{vTag}/{fileName}", repo.MustBeNotEmpty, repo.RedirectDownload)
1349+
m.Get("/tag/*", context.RepoRefByType(git.RefTypeTag), repo.SingleRelease)
1350+
m.Get("/latest", repo.LatestRelease)
1351+
}, ctxDataSet("EnableFeed", setting.Other.EnableFeed))
1352+
m.Get("/releases/attachments/{uuid}", repo.GetAttachment)
1353+
m.Get("/releases/download/{vTag}/{fileName}", repo.RedirectDownload)
13571354
m.Group("/releases", func() {
13581355
m.Get("/new", repo.NewRelease)
13591356
m.Post("/new", web.Bind(forms.NewReleaseForm{}), repo.NewReleasePost)
13601357
m.Post("/delete", repo.DeleteRelease)
13611358
m.Post("/attachments", repo.UploadReleaseAttachment)
13621359
m.Post("/attachments/remove", repo.DeleteAttachment)
1363-
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, context.RepoRef())
1360+
}, reqSignIn, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, context.RepoRef())
13641361
m.Group("/releases", func() {
13651362
m.Get("/edit/*", repo.EditRelease)
13661363
m.Post("/edit/*", web.Bind(forms.EditReleaseForm{}), repo.EditReleasePost)
1367-
}, reqSignIn, repo.MustBeNotEmpty, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, repo.CommitInfoCache)
1368-
}, optSignIn, context.RepoAssignment, reqRepoReleaseReader)
1364+
}, reqSignIn, context.RepoMustNotBeArchived(), reqRepoReleaseWriter, repo.CommitInfoCache)
1365+
}, optSignIn, context.RepoAssignment, repo.MustBeNotEmpty, reqRepoReleaseReader)
13691366
// end "/{username}/{reponame}": repo releases
13701367

13711368
m.Group("/{username}/{reponame}", func() { // to maintain compatibility with old attachments

services/context/repo.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,11 @@ func RepoAssignment(ctx *Context) {
679679

680680
const headRefName = "HEAD"
681681

682-
// RepoRef handles repository reference names when the ref name is not
683-
// explicitly given
684682
func RepoRef() func(*Context) {
685-
// since no ref name is explicitly specified, ok to just use branch
683+
if !setting.IsProd || setting.IsInTesting {
684+
// RepoRef should not be used, the handler should explicit use the ref it needs
685+
return nil
686+
}
686687
return RepoRefByType(git.RefTypeBranch)
687688
}
688689

@@ -776,10 +777,6 @@ func getRefName(ctx *Base, repo *Repository, path string, refType git.RefType) s
776777
return ""
777778
}
778779

779-
type RepoRefByTypeOptions struct {
780-
IgnoreNotExistErr bool
781-
}
782-
783780
func repoRefFullName(typ git.RefType, shortName string) git.RefName {
784781
switch typ {
785782
case git.RefTypeBranch:
@@ -796,8 +793,7 @@ func repoRefFullName(typ git.RefType, shortName string) git.RefName {
796793

797794
// RepoRefByType handles repository reference name for a specific type
798795
// of repository reference
799-
func RepoRefByType(detectRefType git.RefType, opts ...RepoRefByTypeOptions) func(*Context) {
800-
opt := util.OptionalArg(opts)
796+
func RepoRefByType(detectRefType git.RefType) func(*Context) {
801797
return func(ctx *Context) {
802798
var err error
803799
refType := detectRefType
@@ -908,9 +904,6 @@ func RepoRefByType(detectRefType git.RefType, opts ...RepoRefByTypeOptions) func
908904
ctx.RespHeader().Set("Link", fmt.Sprintf(`<%s>; rel="canonical"`, canonicalURL))
909905
}
910906
} else {
911-
if opt.IgnoreNotExistErr {
912-
return
913-
}
914907
ctx.NotFound("RepoRef invalid repo", fmt.Errorf("branch or tag not exist: %s", refShortName))
915908
return
916909
}

0 commit comments

Comments
 (0)