@@ -58,6 +58,7 @@ type Repository struct {
5858 Commit * git.Commit
5959 Tag * git.Tag
6060 GitRepo * git.Repository
61+ RefName string
6162 BranchName string
6263 TagName string
6364 TreePath string
@@ -190,9 +191,9 @@ func (r *Repository) BranchNameSubURL() string {
190191 case r .IsViewBranch :
191192 return "branch/" + r .BranchName
192193 case r .IsViewTag :
193- return "tag/" + r .BranchName
194+ return "tag/" + r .TagName
194195 case r .IsViewCommit :
195- return "commit/" + r .BranchName
196+ return "commit/" + r .CommitID
196197 }
197198 log .Error ("Unknown view type for repo: %v" , r )
198199 return ""
@@ -562,8 +563,6 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
562563 ctx .Data ["Branches" ] = brs
563564 ctx .Data ["BranchesCount" ] = len (brs )
564565
565- ctx .Data ["TagName" ] = ctx .Repo .TagName
566-
567566 // If not branch selected, try default one.
568567 // If default branch doesn't exists, fall back to some other branch.
569568 if len (ctx .Repo .BranchName ) == 0 {
@@ -572,9 +571,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
572571 } else if len (brs ) > 0 {
573572 ctx .Repo .BranchName = brs [0 ]
574573 }
574+ ctx .Repo .RefName = ctx .Repo .BranchName
575575 }
576576 ctx .Data ["BranchName" ] = ctx .Repo .BranchName
577- ctx .Data ["CommitID" ] = ctx .Repo .CommitID
578577
579578 // People who have push access or have forked repository can propose a new pull request.
580579 canPush := ctx .Repo .CanWrite (models .UnitTypeCode ) || (ctx .IsSigned && ctx .User .HasForkedRepo (ctx .Repo .Repository .ID ))
@@ -759,7 +758,6 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
759758 // Get default branch.
760759 if len (ctx .Params ("*" )) == 0 {
761760 refName = ctx .Repo .Repository .DefaultBranch
762- ctx .Repo .BranchName = refName
763761 if ! ctx .Repo .GitRepo .IsBranchExist (refName ) {
764762 brs , _ , err := ctx .Repo .GitRepo .GetBranches (0 , 0 )
765763 if err != nil {
@@ -773,6 +771,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
773771 }
774772 refName = brs [0 ]
775773 }
774+ ctx .Repo .RefName = refName
775+ ctx .Repo .BranchName = refName
776776 ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetBranchCommit (refName )
777777 if err != nil {
778778 ctx .ServerError ("GetBranchCommit" , err )
@@ -783,9 +783,10 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
783783
784784 } else {
785785 refName = getRefName (ctx , refType )
786- ctx .Repo .BranchName = refName
786+ ctx .Repo .RefName = refName
787787 if refType .RefTypeIncludesBranches () && ctx .Repo .GitRepo .IsBranchExist (refName ) {
788788 ctx .Repo .IsViewBranch = true
789+ ctx .Repo .BranchName = refName
789790
790791 ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetBranchCommit (refName )
791792 if err != nil {
@@ -796,6 +797,8 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
796797
797798 } else if refType .RefTypeIncludesTags () && ctx .Repo .GitRepo .IsTagExist (refName ) {
798799 ctx .Repo .IsViewTag = true
800+ ctx .Repo .TagName = refName
801+
799802 ctx .Repo .Commit , err = ctx .Repo .GitRepo .GetTagCommit (refName )
800803 if err != nil {
801804 ctx .ServerError ("GetTagCommit" , err )
@@ -837,6 +840,7 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
837840
838841 ctx .Data ["BranchName" ] = ctx .Repo .BranchName
839842 ctx .Data ["BranchNameSubURL" ] = ctx .Repo .BranchNameSubURL ()
843+ ctx .Data ["TagName" ] = ctx .Repo .TagName
840844 ctx .Data ["CommitID" ] = ctx .Repo .CommitID
841845 ctx .Data ["TreePath" ] = ctx .Repo .TreePath
842846 ctx .Data ["IsViewBranch" ] = ctx .Repo .IsViewBranch
0 commit comments