@@ -518,6 +518,22 @@ func RepoRef() macaron.Handler {
518
518
return RepoRefByType (RepoRefBranch )
519
519
}
520
520
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
+
521
537
func getRefNameFromPath (ctx * Context , path string , isExist func (string ) bool ) string {
522
538
refName := ""
523
539
parts := strings .Split (path , "/" )
@@ -623,7 +639,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
623
639
} else {
624
640
refName = getRefName (ctx , refType )
625
641
ctx .Repo .BranchName = refName
626
- if ctx .Repo .GitRepo .IsBranchExist (refName ) {
642
+ if refType . RefTypeIncludesBranches () && ctx .Repo .GitRepo .IsBranchExist (refName ) {
627
643
ctx .Repo .IsViewBranch = true
628
644
629
645
ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetBranchCommit (refName )
@@ -633,7 +649,7 @@ func RepoRefByType(refType RepoRefType) macaron.Handler {
633
649
}
634
650
ctx .Repo .CommitID = ctx .Repo .Commit .ID .String ()
635
651
636
- } else if ctx .Repo .GitRepo .IsTagExist (refName ) {
652
+ } else if refType . RefTypeIncludesTags () && ctx .Repo .GitRepo .IsTagExist (refName ) {
637
653
ctx .Repo .IsViewTag = true
638
654
ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetTagCommit (refName )
639
655
if err != nil {
0 commit comments