Fixed comparison of tags & branches

This commit is contained in:
Rajat Jain 2021-02-04 18:02:21 +05:30
parent af6510fd17
commit b479892563

View File

@ -476,7 +476,7 @@ func ParseCompareInfo(c *context.Context) (*db.User, *db.Repository, *git.Reposi
c.Repo.PullRequest.SameRepo = isSameRepo
// Check if base branch is valid.
if !c.Repo.GitRepo.HasBranch(baseBranch) {
if !c.Repo.GitRepo.HasBranch(baseBranch) && !c.Repo.GitRepo.HasTag(baseBranch) {
c.NotFound()
return nil, nil, nil, nil, "", ""
}
@ -517,7 +517,7 @@ func ParseCompareInfo(c *context.Context) (*db.User, *db.Repository, *git.Reposi
}
// Check if head branch is valid.
if !headGitRepo.HasBranch(headBranch) {
if !headGitRepo.HasBranch(headBranch) && !headGitRepo.HasTag(headBranch) {
c.NotFound()
return nil, nil, nil, nil, "", ""
}
@ -563,10 +563,13 @@ func PrepareCompareDiff(
c.Data["CommitRepoLink"] = headRepo.Link()
headCommitID, err := headGitRepo.BranchCommitID(headBranch)
if err != nil {
headCommitID, err = headGitRepo.TagCommitID(headBranch)
if err != nil {
c.Error(err, "get head branch commit ID")
return false
}
}
c.Data["AfterCommitID"] = headCommitID
if headCommitID == meta.MergeBase {