diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index 237e53413f767..66040cbc6ec13 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -738,24 +738,59 @@ func ViewPullCommits(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplPullCommits)
}
+func ViewPullCommitFiles(ctx *context.Context) {
+ ctx.Data["PageIsPullCommits"] = true
+ issue := checkPullInfo(ctx)
+ if ctx.Written() {
+ return
+ }
+ var prInfo *git.CompareInfo
+ if issue.PullRequest.HasMerged {
+ prInfo = PrepareMergedViewPullInfo(ctx, issue)
+ } else {
+ prInfo = PrepareViewPullInfo(ctx, issue)
+ }
+
+ if ctx.Written() {
+ return
+ } else if prInfo == nil {
+ ctx.NotFound("ViewPullCommits", nil)
+ return
+ }
+
+ index := -1
+ for i, commit := range prInfo.Commits {
+ if commit.ID.String() == ctx.Params("sha") {
+ index = i
+ break
+ }
+ }
+ if index == -1 {
+ ctx.NotFound("ViewPullCommitFiles", nil)
+ return
+ }
+
+ var startCommitID string
+ if index == len(prInfo.Commits)-1 {
+ startCommitID = issue.PullRequest.MergeBase
+ } else {
+ startCommitID = prInfo.Commits[index+1].ID.String()
+ }
+
+ baseViewPullCommitFiles(ctx, issue.PullRequest, startCommitID, ctx.Params("sha"))
+}
+
// ViewPullFiles render pull request changed files list page
func ViewPullFiles(ctx *context.Context) {
- ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullFiles"] = true
-
+ var startCommitID string
+ var endCommitID string
+ var prInfo *git.CompareInfo
issue := checkPullInfo(ctx)
if ctx.Written() {
return
}
pull := issue.PullRequest
-
- var (
- startCommitID string
- endCommitID string
- gitRepo = ctx.Repo.GitRepo
- )
-
- var prInfo *git.CompareInfo
if pull.HasMerged {
prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
@@ -769,7 +804,7 @@ func ViewPullFiles(ctx *context.Context) {
return
}
- headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
+ headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
@@ -777,6 +812,18 @@ func ViewPullFiles(ctx *context.Context) {
startCommitID = prInfo.MergeBase
endCommitID = headCommitID
+ baseViewPullCommitFiles(ctx, pull, startCommitID, endCommitID)
+}
+
+func showOutdatedComments(ctx *context.Context) bool {
+ show, ok := ctx.Data["ShowOutdatedComments"].(bool)
+ return ok && show
+}
+
+func baseViewPullCommitFiles(ctx *context.Context, pull *issues_model.PullRequest, startCommitID, endCommitID string) {
+ ctx.Data["PageIsPullList"] = true
+
+ gitRepo := ctx.Repo.GitRepo
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
@@ -801,6 +848,8 @@ func ViewPullFiles(ctx *context.Context) {
var methodWithError string
var diff *gitdiff.Diff
+ var err error
+ issue := pull.Issue
if !ctx.IsSigned {
diff, err = gitdiff.GetDiff(gitRepo, diffOptions, files...)
methodWithError = "GetDiff"
@@ -818,7 +867,7 @@ func ViewPullFiles(ctx *context.Context) {
"numberOfViewedFiles": diff.NumViewedFiles,
}
- if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil {
+ if err = diff.LoadComments(ctx, issue, ctx.Doer, showOutdatedComments(ctx)); err != nil {
ctx.ServerError("LoadComments", err)
return
}
diff --git a/routers/web/repo/pull_review.go b/routers/web/repo/pull_review.go
index c2271750c4d1d..77deb7583e6e5 100644
--- a/routers/web/repo/pull_review.go
+++ b/routers/web/repo/pull_review.go
@@ -160,7 +160,7 @@ func UpdateResolveConversation(ctx *context.Context) {
}
func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
- comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, ctx.Data["ShowOutdatedComments"].(bool))
+ comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, showOutdatedComments(ctx))
if err != nil {
ctx.ServerError("FetchCodeCommentsByLine", err)
return
diff --git a/routers/web/web.go b/routers/web/web.go
index 0b519614453a7..578f7e6baf529 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -1280,6 +1280,7 @@ func registerRoutes(m *web.Route) {
m.Get(".diff", repo.DownloadPullDiff)
m.Get(".patch", repo.DownloadPullPatch)
m.Get("/commits", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommits)
+ m.Get("/commits/{sha}", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommitFiles)
m.Post("/merge", context.RepoMustNotBeArchived(), web.Bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
m.Post("/update", repo.UpdatePullRequest)
diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl
index ef9d0654566f5..640bd5addaab4 100644
--- a/templates/repo/commits_list.tmpl
+++ b/templates/repo/commits_list.tmpl
@@ -43,6 +43,8 @@
{{end}}
{{if $.PageIsWiki}}
+ {{else if $.PageIsPullCommits}}
+
{{else if $.Reponame}}
{{else}}