From 0b5bf84622f1c82875df34b276f90d7576099cc6 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Sat, 9 Nov 2019 20:53:33 +0100 Subject: [PATCH 1/2] only view branch or tag if it match refName. --- modules/context/repo.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 8a9c9e4b8cf7..6dd6ced2c341 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -518,6 +518,22 @@ func RepoRef() macaron.Handler { return RepoRefByType(RepoRefBranch) } +// RefTypeIncludesBranches returns true if ref type can be a branch +func (rt *RepoRefType) RefTypeIncludesBranches() bool { + if *rt == RepoRefLegacy || *rt == RepoRefAny || *rt == RepoRefBranch { + return true + } + return false +} + +// RefTypeIncludesTags returns true if ref type can be a tag +func (rt *RepoRefType) RefTypeIncludesTags() bool { + if *rt == RepoRefLegacy || *rt == RepoRefAny || *rt == RepoRefTag { + return true + } + return false +} + func getRefNameFromPath(ctx *Context, path string, isExist func(string) bool) string { refName := "" parts := strings.Split(path, "/") @@ -623,7 +639,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler { } else { refName = getRefName(ctx, refType) ctx.Repo.BranchName = refName - if ctx.Repo.GitRepo.IsBranchExist(refName) { + if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) { ctx.Repo.IsViewBranch = true ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) @@ -633,7 +649,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler { } ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() - } else if ctx.Repo.GitRepo.IsTagExist(refName) { + } else if refType.RefTypeIncludesTags() && ctx.Repo.GitRepo.IsTagExist(refName) { ctx.Repo.IsViewTag = true ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName) if err != nil { From 02a0f4b58b780b32682883aba0b0ee4efc76ed47 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Mon, 11 Nov 2019 07:07:03 +0000 Subject: [PATCH 2/2] remove pointer in method --- modules/context/repo.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 6dd6ced2c341..66f662ea0bc1 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -519,16 +519,16 @@ func RepoRef() macaron.Handler { } // RefTypeIncludesBranches returns true if ref type can be a branch -func (rt *RepoRefType) RefTypeIncludesBranches() bool { - if *rt == RepoRefLegacy || *rt == RepoRefAny || *rt == RepoRefBranch { +func (rt RepoRefType) RefTypeIncludesBranches() bool { + if rt == RepoRefLegacy || rt == RepoRefAny || rt == RepoRefBranch { return true } return false } // RefTypeIncludesTags returns true if ref type can be a tag -func (rt *RepoRefType) RefTypeIncludesTags() bool { - if *rt == RepoRefLegacy || *rt == RepoRefAny || *rt == RepoRefTag { +func (rt RepoRefType) RefTypeIncludesTags() bool { + if rt == RepoRefLegacy || rt == RepoRefAny || rt == RepoRefTag { return true } return false