@ -391,7 +391,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
if rootRepo != nil &&
rootRepo . ID != headRepo . ID &&
rootRepo . ID != baseRepo . ID {
perm , branches , err := getBranchesForRepo ( ctx . User , rootRepo )
perm , branches , tags , err := getBranchesAndTag sForRepo ( ctx . User , rootRepo )
if err != nil {
ctx . ServerError ( "GetBranchesForRepo" , err )
return nil , nil , nil , nil , "" , ""
@ -399,19 +399,20 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
if perm {
ctx . Data [ "RootRepo" ] = rootRepo
ctx . Data [ "RootRepoBranches" ] = branches
ctx . Data [ "RootRepoTags" ] = tags
}
}
// If we have a ownForkRepo and it's different from:
// 1. The computed base
// 2. The computed hea
// 2. The computed head
// 3. The rootRepo (if we have one)
// then get the branches from it.
if ownForkRepo != nil &&
ownForkRepo . ID != headRepo . ID &&
ownForkRepo . ID != baseRepo . ID &&
( rootRepo == nil || ownForkRepo . ID != rootRepo . ID ) {
perm , branches , err := getBranchesForRepo ( ctx . User , ownForkRepo )
perm , branches , tags , err := getBranchesAndTag sForRepo ( ctx . User , ownForkRepo )
if err != nil {
ctx . ServerError ( "GetBranchesForRepo" , err )
return nil , nil , nil , nil , "" , ""
@ -419,6 +420,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
if perm {
ctx . Data [ "OwnForkRepo" ] = ownForkRepo
ctx . Data [ "OwnForkRepoBranches" ] = branches
ctx . Data [ "OwnForkRepoTags" ] = tags
}
}
@ -572,25 +574,29 @@ func PrepareCompareDiff(
return false
}
func getBranchesForRepo ( user * models . User , repo * models . Repository ) ( bool , [ ] string , error ) {
func getBranchesAndTags ForRepo ( user * models . User , repo * models . Repository ) ( bool , [ ] string , [ ] string , error ) {
perm , err := models . GetUserRepoPermission ( repo , user )
if err != nil {
return false , nil , err
return false , nil , nil , err
}
if ! perm . CanRead ( models . UnitTypeCode ) {
return false , nil , nil
return false , nil , nil , nil
}
gitRepo , err := git . OpenRepository ( repo . RepoPath ( ) )
if err != nil {
return false , nil , err
return false , nil , nil , err
}
defer gitRepo . Close ( )
branches , _ , err := gitRepo . GetBranches ( 0 , 0 )
if err != nil {
return false , nil , err
return false , nil , nil , err
}
return true , branches , nil
tags , err := gitRepo . GetTags ( )
if err != nil {
return false , nil , nil , err
}
return true , branches , tags , nil
}
// CompareDiff show different from one commit to another commit
@ -608,7 +614,14 @@ func CompareDiff(ctx *context.Context) {
return
}
if ctx . Data [ "PageIsComparePull" ] == true {
baseGitRepo := ctx . Repo . GitRepo
baseTags , err := baseGitRepo . GetTags ( )
if err != nil {
ctx . ServerError ( "GetTags" , err )
return
}
ctx . Data [ "Tags" ] = baseTags
headBranches , _ , err := headGitRepo . GetBranches ( 0 , 0 )
if err != nil {
ctx . ServerError ( "GetBranches" , err )
@ -616,6 +629,14 @@ func CompareDiff(ctx *context.Context) {
}
ctx . Data [ "HeadBranches" ] = headBranches
headTags , err := headGitRepo . GetTags ( )
if err != nil {
ctx . ServerError ( "GetTags" , err )
return
}
ctx . Data [ "HeadTags" ] = headTags
if ctx . Data [ "PageIsComparePull" ] == true {
pr , err := models . GetUnmergedPullRequest ( headRepo . ID , ctx . Repo . Repository . ID , headBranch , baseBranch )
if err != nil {
if ! models . IsErrPullRequestNotExist ( err ) {