@@ -518,6 +518,22 @@ func RepoRef() macaron.Handler {
518518 return RepoRefByType (RepoRefBranch )
519519}
520520
521+ // RefTypeIncludesBranches returns true if ref type can be a branch
522+ func (rt RepoRefType ) RefTypeIncludesBranches () bool {
523+ if rt == RepoRefLegacy || rt == RepoRefAny || rt == RepoRefBranch {
524+ return true
525+ }
526+ return false
527+ }
528+
529+ // RefTypeIncludesTags returns true if ref type can be a tag
530+ func (rt RepoRefType ) RefTypeIncludesTags () bool {
531+ if rt == RepoRefLegacy || rt == RepoRefAny || rt == RepoRefTag {
532+ return true
533+ }
534+ return false
535+ }
536+
521537func getRefNameFromPath (ctx * Context , path string , isExist func (string ) bool ) string {
522538 refName := ""
523539 parts := strings .Split (path , "/" )
@@ -623,7 +639,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
623639 } else {
624640 refName = getRefName (ctx , refType )
625641 ctx .Repo .BranchName = refName
626- if ctx .Repo .GitRepo .IsBranchExist (refName ) {
642+ if refType . RefTypeIncludesBranches () && ctx .Repo .GitRepo .IsBranchExist (refName ) {
627643 ctx .Repo .IsViewBranch = true
628644
629645 ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetBranchCommit (refName )
@@ -633,7 +649,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
633649 }
634650 ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
635651
636- } else if ctx .Repo .GitRepo .IsTagExist (refName ) {
652+ } else if refType . RefTypeIncludesTags () && ctx .Repo .GitRepo .IsTagExist (refName ) {
637653 ctx .Repo .IsViewTag = true
638654 ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetTagCommit (refName )
639655 if err != nil {
0 commit comments