Skip to content

Fix files/commits of merged PRs #2970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down