Browse Source

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

* only view branch or tag if it match refName.

* remove pointer in method
tags/v1.11.0-rc1
David Svantesson 4 years ago
parent
commit
8d9e625f83
1 changed files with 18 additions and 2 deletions
  1. 18
    2
      modules/context/repo.go

+ 18
- 2
modules/context/repo.go View File

return RepoRefByType(RepoRefBranch) 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 { func getRefNameFromPath(ctx *Context, path string, isExist func(string) bool) string {
refName := "" refName := ""
parts := strings.Split(path, "/") parts := strings.Split(path, "/")
} else { } else {
refName = getRefName(ctx, refType) refName = getRefName(ctx, refType)
ctx.Repo.BranchName = refName ctx.Repo.BranchName = refName
if ctx.Repo.GitRepo.IsBranchExist(refName) {
if refType.RefTypeIncludesBranches() && ctx.Repo.GitRepo.IsBranchExist(refName) {
ctx.Repo.IsViewBranch = true ctx.Repo.IsViewBranch = true


ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
} }
ctx.Repo.CommitID = ctx.Repo.Commit.ID.String() 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.IsViewTag = true
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName) ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetTagCommit(refName)
if err != nil { if err != nil {

Loading…
Cancel
Save