diff options
Diffstat (limited to 'routers/repo/compare.go')
-rw-r--r-- | routers/repo/compare.go | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/routers/repo/compare.go b/routers/repo/compare.go index a658374d9b..d02ea0b160 100644 --- a/routers/repo/compare.go +++ b/routers/repo/compare.go @@ -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 := getBranchesAndTagsForRepo(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 := getBranchesAndTagsForRepo(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 getBranchesAndTagsForRepo(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,14 +614,29 @@ func CompareDiff(ctx *context.Context) { return } - if ctx.Data["PageIsComparePull"] == true { - headBranches, _, err := headGitRepo.GetBranches(0, 0) - if err != nil { - ctx.ServerError("GetBranches", err) - return - } - ctx.Data["HeadBranches"] = headBranches + 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) + return + } + 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) { |