Commit 5423e6e2 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'zj-workhorse-format-patch' into 'master'

Workhorse to serve email diffs

See merge request !4590
parents d171ff17 db0a6c10
......@@ -6,6 +6,7 @@ v 8.10.0 (unreleased)
- Wrap code blocks on Activies and Todos page. !4783 (winniehell)
- Display last commit of deleted branch in push events !4699 (winniehell)
- Add Sidekiq queue duration to transaction metrics.
- Let Workhorse serve format-patch diffs
- Make images fit to the size of the viewport !4810
- Fix check for New Branch button on Issue page !4630 (winniehell)
- Fix MR-auto-close text added to description. !4836
......
......@@ -59,7 +59,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController
respond_to do |format|
format.html
format.json { render json: @merge_request }
format.patch { render text: @merge_request.to_patch }
format.patch do
headers.store(*Gitlab::Workhorse.send_git_patch(@project.repository,
@merge_request.diff_base_commit.id,
@merge_request.last_commit.id))
headers['Content-Disposition'] = 'inline'
head :ok
end
format.diff do
return render_404 unless @merge_request.diff_refs
......
......@@ -319,13 +319,6 @@ class MergeRequest < ActiveRecord::Base
)
end
# Returns the commit as a series of email patches.
#
# see "git format-patch"
def to_patch
target_project.repository.format_patch(diff_base_commit.sha, source_sha)
end
def hook_attrs
attrs = {
source: source_project.try(:hook_attrs),
......
......@@ -52,6 +52,19 @@ module Gitlab
]
end
def send_git_patch(repository, from, to)
params = {
'RepoPath' => repository.path_to_repo,
'ShaFrom' => from,
'ShaTo' => to
}
[
SEND_DATA_HEADER,
"git-format-patch:#{encode(params)}"
]
end
protected
def encode(hash)
......
......@@ -96,26 +96,14 @@ describe Projects::MergeRequestsController do
end
describe "as patch" do
include_examples "export merge as", :patch
let(:format) { :patch }
it "should really be a git email patch with commit" do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid, format: format)
expect(response.body[0..100]).to start_with("From #{merge_request.commits.last.id}")
end
it "should contain git diffs" do
it 'triggers workhorse to serve the request' do
get(:show,
namespace_id: project.namespace.to_param,
project_id: project.to_param,
id: merge_request.iid,
format: format)
format: :patch)
expect(response.body).to match(/^diff --git/)
expect(response.headers['Gitlab-Workhorse-Send-Data']).to start_with("git-format-patch:")
end
end
end
......
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