diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2019-11-11 08:37:28 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-11 15:37:28 +0800 |
commit | 8d9e625f83bf05086cfb72087548d203aff96db3 (patch) | |
tree | 327b26a3094525dbec25a8ad83f1502050806861 /modules/context/repo.go | |
parent | 273a24f22676b73a648fd2a5467e385ec41e84e2 (diff) | |
download | gitea-8d9e625f83bf05086cfb72087548d203aff96db3.tar.gz gitea-8d9e625f83bf05086cfb72087548d203aff96db3.zip |
Only view branch or tag if it match refType requested. (#8899)
* only view branch or tag if it match refName.
* remove pointer in method
Diffstat (limited to 'modules/context/repo.go')
-rw-r--r-- | modules/context/repo.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go index 8a9c9e4b8c..66f662ea0b 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 { |