diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-11-25 05:47:19 -0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-11-25 21:47:19 +0800 |
commit | 40c545ddbccc65aa607a2153d38b56cc3bb99be9 (patch) | |
tree | 9cf9bdef087d4776f7b0d8facab3df7537d8caa2 /routers | |
parent | 183da4c2c1611d845f0198a3ddeeddd85c745243 (diff) | |
download | gitea-40c545ddbccc65aa607a2153d38b56cc3bb99be9.tar.gz gitea-40c545ddbccc65aa607a2153d38b56cc3bb99be9.zip |
Fix files/commits of merged PRs (#2937)
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/pull.go | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go index ac0d36c278..14b0928734 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -257,12 +257,24 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { setMergeTarget(ctx, pull) ctx.Data["HasMerged"] = true - ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) + mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) + if err != nil { + ctx.Handle(500, "GetCommit", err) + return + } + // the ID of the last commit in the PR (not including the merge commit) + endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) + if err != nil { + ctx.Handle(500, "ParentID", err) + return + } + + ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, endCommitID.String()) if err != nil { ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) return } - ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, pull.MergedCommitID) + ctx.Data["NumFiles"], err = ctx.Repo.GitRepo.FilesCountBetween(pull.MergeBase, endCommitID.String()) if err != nil { ctx.Handle(500, "Repo.GitRepo.FilesCountBetween", err) return @@ -338,19 +350,19 @@ func ViewPullCommits(ctx *context.Context) { ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name - startCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergeBase) + mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) if err != nil { ctx.Handle(500, "Repo.GitRepo.GetCommit", err) return } - endCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) + endCommitID, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) if err != nil { - ctx.Handle(500, "Repo.GitRepo.GetCommit", err) + ctx.Handle(500, "ParentID", err) return } - commits, err = ctx.Repo.GitRepo.CommitsBetween(endCommit, startCommit) + commits, err = ctx.Repo.GitRepo.CommitsBetweenIDs(endCommitID.String(), pull.MergeBase) if err != nil { - ctx.Handle(500, "Repo.GitRepo.CommitsBetween", err) + ctx.Handle(500, "Repo.GitRepo.CommitsBetweenIDs", err) return } } else { @@ -402,7 +414,17 @@ func ViewPullFiles(ctx *context.Context) { diffRepoPath = ctx.Repo.GitRepo.Path startCommitID = pull.MergeBase - endCommitID = pull.MergedCommitID + mergedCommit, err := ctx.Repo.GitRepo.GetCommit(pull.MergedCommitID) + if err != nil { + ctx.Handle(500, "GetCommit", err) + return + } + endCommitSha, err := mergedCommit.ParentID(mergedCommit.ParentCount() - 1) + if err != nil { + ctx.Handle(500, "ParentID", err) + return + } + endCommitID = endCommitSha.String() gitRepo = ctx.Repo.GitRepo headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) |