summaryrefslogtreecommitdiffstats
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-03-31 14:42:44 +0100
committerGitHub <noreply@github.com>2020-03-31 16:42:44 +0300
commit2c25e75dca62850ddc328ed46c7b7d27b61be90b (patch)
treef48395e914269304e236d032f0fc642cd5de62a7 /routers/repo/pull.go
parent73cf0e2614263c8c4ad6d55d06e753b28d2b6091 (diff)
downloadgitea-2c25e75dca62850ddc328ed46c7b7d27b61be90b.tar.gz
gitea-2c25e75dca62850ddc328ed46c7b7d27b61be90b.zip
Various Merge Base fixes (#10786)
* Fix broken merge base migration v128 for merged PR * Allow PRs with deleted base branches to still show diff * as per @lunny Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 5fb5bfa2bb..c29cfb81b2 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -308,7 +308,6 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
pull.MergeBase, pull.GetGitRefName())
-
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
ctx.Data["IsPullRequestBroken"] = true
@@ -360,9 +359,40 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
ctx.Data["IsPullRequestBroken"] = true
ctx.Data["BaseTarget"] = pull.BaseBranch
ctx.Data["HeadTarget"] = pull.HeadBranch
- ctx.Data["NumCommits"] = 0
- ctx.Data["NumFiles"] = 0
- return nil
+
+ sha, err := baseGitRepo.GetRefCommitID(pull.GetGitRefName())
+ if err != nil {
+ ctx.ServerError(fmt.Sprintf("GetRefCommitID(%s)", pull.GetGitRefName()), err)
+ return nil
+ }
+ commitStatuses, err := models.GetLatestCommitStatus(repo, sha, 0)
+ if err != nil {
+ ctx.ServerError("GetLatestCommitStatus", err)
+ return nil
+ }
+ if len(commitStatuses) > 0 {
+ ctx.Data["LatestCommitStatuses"] = commitStatuses
+ ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
+ }
+
+ compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
+ pull.MergeBase, pull.GetGitRefName())
+ if err != nil {
+ if strings.Contains(err.Error(), "fatal: Not a valid object name") {
+ ctx.Data["IsPullRequestBroken"] = true
+ ctx.Data["BaseTarget"] = pull.BaseBranch
+ ctx.Data["NumCommits"] = 0
+ ctx.Data["NumFiles"] = 0
+ return nil
+ }
+
+ ctx.ServerError("GetCompareInfo", err)
+ return nil
+ }
+
+ ctx.Data["NumCommits"] = compareInfo.Commits.Len()
+ ctx.Data["NumFiles"] = compareInfo.NumFiles
+ return compareInfo
}
var headBranchExist bool