diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4d9d9bc60e66f..8463411f8753c 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1654,6 +1654,10 @@ pulls.switch_comparison_type = Switch comparison type pulls.switch_head_and_base = Switch head and base pulls.filter_branch = Filter branch pulls.no_results = No results found. +pulls.show_all_commits = Show all commits +pulls.show_all_commits.description = Show all commits of this PR +pulls.showing_only_single_commit = Showing only changes of commit %[1]s +pulls.select_commits = Filter commit pulls.nothing_to_compare = These branches are equal. There is no need to create a pull request. pulls.nothing_to_compare_and_allow_empty_pr = These branches are equal. This PR will be empty. pulls.has_pull_request = `A pull request between these branches already exists: %[2]s#%[3]d` diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index f2a58a35a78a8..3bad07283085a 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -683,6 +683,8 @@ func ViewPullCommits(ctx *context.Context) { // ViewPullFiles render pull request changed files list page func ViewPullFiles(ctx *context.Context) { + commitToShow := ctx.Params("sha") + ctx.Data["PageIsPullList"] = true ctx.Data["PageIsPullFiles"] = true @@ -719,8 +721,16 @@ func ViewPullFiles(ctx *context.Context) { } startCommitID = prInfo.MergeBase - endCommitID = headCommitID + if len(commitToShow) > 0 { + endCommitID = commitToShow + ctx.Data["IsShowingAllCommits"] = false + } else { + endCommitID = headCommitID + ctx.Data["IsShowingAllCommits"] = true + } + + ctx.Data["Commits"] = prInfo.Commits ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["AfterCommitID"] = endCommitID @@ -732,14 +742,30 @@ func ViewPullFiles(ctx *context.Context) { if fileOnly && (len(files) == 2 || len(files) == 1) { maxLines, maxFiles = -1, -1 } - diffOptions := &gitdiff.DiffOptions{ - BeforeCommitID: startCommitID, - AfterCommitID: endCommitID, - SkipTo: ctx.FormString("skip-to"), - MaxLines: maxLines, - MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, - MaxFiles: maxFiles, - WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + + var diffOptions *gitdiff.DiffOptions + + // show only a single commit for this pr + if len(commitToShow) > 0 { + diffOptions = &gitdiff.DiffOptions{ + AfterCommitID: endCommitID, + SkipTo: ctx.FormString("skip-to"), + MaxLines: maxLines, + MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, + MaxFiles: maxFiles, + WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + } + } else { + // show full PR diff + diffOptions = &gitdiff.DiffOptions{ + BeforeCommitID: startCommitID, + AfterCommitID: endCommitID, + SkipTo: ctx.FormString("skip-to"), + MaxLines: maxLines, + MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, + MaxFiles: maxFiles, + WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + } } var methodWithError string diff --git a/routers/web/web.go b/routers/web/web.go index 26ad2d54c3a32..bc7164770c5f9 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1286,6 +1286,7 @@ func registerRoutes(m *web.Route) { m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest) m.Group("/files", func() { m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFiles) + m.Get("/{sha}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFiles) m.Group("/reviews", func() { m.Get("/new_comment", repo.RenderNewCodeCommentForm) m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 1198452f7e567..1c44628a3ef4a 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -43,11 +43,19 @@ {{end}} {{template "repo/diff/whitespace_dropdown" .}} {{template "repo/diff/options_dropdown" .}} + {{if .PageIsPullFiles}} + {{template "repo/diff/commits_dropdown" .}} + {{end}} {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}} {{template "repo/diff/new_review" .}} {{end}} + {{if and (not .IsShowingAllCommits) .PageIsPullFiles}} +
+ {{end}}