Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only view branch or tag if it match refType requested. #8899

Merged
merged 6 commits into from
Nov 11, 2019
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
lafriks marked this conversation as resolved.
Show resolved Hide resolved
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, "/")
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down