Commit 0a3f5adf authored by Robert Speicher's avatar Robert Speicher Committed by Rémy Coutable

Merge branch 'patch/fix-mergerequest-diff' into 'master'

Fix Raw / Rendered diff producing different results on merge requests

The raw diff endpoint (`merge_requests/####.diff`) produces a diff based on `target_branch` instead of the original branching point. Same is valid for `merge_requests/####.patch`.

Fixes #14680, #3017

See merge request !3450
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent e5d0af56
...@@ -5,6 +5,7 @@ v 8.6.3 (unreleased) ...@@ -5,6 +5,7 @@ v 8.6.3 (unreleased)
v 8.6.3 (unreleased) v 8.6.3 (unreleased)
- Destroy related todos when an Issue/MR is deleted. !3376 - Destroy related todos when an Issue/MR is deleted. !3376
- Fix error 500 when target is nil on todo list. !3376 - Fix error 500 when target is nil on todo list. !3376
- Fix raw/rendered diff producing different results on merge requests. !3450
v 8.6.2 v 8.6.2
- Fix dropdown alignment. !3298 - Fix dropdown alignment. !3298
......
...@@ -57,8 +57,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -57,8 +57,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: @merge_request } format.json { render json: @merge_request }
format.diff { render text: @merge_request.to_diff(current_user) } format.diff { render text: @merge_request.to_diff }
format.patch { render text: @merge_request.to_patch(current_user) } format.patch { render text: @merge_request.to_patch }
end end
end end
......
...@@ -331,15 +331,15 @@ class MergeRequest < ActiveRecord::Base ...@@ -331,15 +331,15 @@ class MergeRequest < ActiveRecord::Base
# Returns the raw diff for this merge request # Returns the raw diff for this merge request
# #
# see "git diff" # see "git diff"
def to_diff(current_user) def to_diff
target_project.repository.diff_text(target_branch, source_sha) target_project.repository.diff_text(diff_base_commit.sha, source_sha)
end end
# Returns the commit as a series of email patches. # Returns the commit as a series of email patches.
# #
# see "git format-patch" # see "git format-patch"
def to_patch(current_user) def to_patch
target_project.repository.format_patch(target_branch, source_sha) target_project.repository.format_patch(diff_base_commit.sha, source_sha)
end end
def hook_attrs def hook_attrs
......
...@@ -63,7 +63,7 @@ describe Projects::MergeRequestsController do ...@@ -63,7 +63,7 @@ describe Projects::MergeRequestsController do
id: merge_request.iid, id: merge_request.iid,
format: format) format: format)
expect(response.body).to eq((merge_request.send(:"to_#{format}",user)).to_s) expect(response.body).to eq((merge_request.send(:"to_#{format}")).to_s)
end end
it "should not escape Html" do it "should not escape Html" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment