Commit ddec2ed0 authored by Douwe Maan's avatar Douwe Maan

Add send_git_patch helper

parent 5ffb848e
...@@ -58,14 +58,17 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -58,14 +58,17 @@ 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 do
render json: @merge_request
end
format.patch do format.patch do
headers.store(*Gitlab::Workhorse.send_git_patch(@project.repository, return render_404 unless @merge_request.diff_refs
@merge_request.diff_base_commit.id,
@merge_request.last_commit.id)) send_git_patch @project.repository, @merge_request.diff_refs
headers['Content-Disposition'] = 'inline'
head :ok
end end
format.diff do format.diff do
return render_404 unless @merge_request.diff_refs return render_404 unless @merge_request.diff_refs
......
# Helpers to send Git blobs, diffs or archives through Workhorse. # Helpers to send Git blobs, diffs, patches or archives through Workhorse.
# Workhorse will also serve files when using `send_file`. # Workhorse will also serve files when using `send_file`.
module WorkhorseHelper module WorkhorseHelper
# Send a Git blob through Workhorse # Send a Git blob through Workhorse
...@@ -16,6 +16,13 @@ module WorkhorseHelper ...@@ -16,6 +16,13 @@ module WorkhorseHelper
head :ok head :ok
end end
# Send a Git patch through Workhorse
def send_git_patch(repository, diff_refs)
headers.store(*Gitlab::Workhorse.send_git_patch(repository, diff_refs))
headers['Content-Disposition'] = 'inline'
head :ok
end
# Archive a Git repository and send it through Workhorse # Archive a Git repository and send it through Workhorse
def send_git_archive(repository, ref:, format:) def send_git_archive(repository, ref:, format:)
headers.store(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format)) headers.store(*Gitlab::Workhorse.send_git_archive(repository, ref: ref, format: format))
......
...@@ -50,11 +50,11 @@ module Gitlab ...@@ -50,11 +50,11 @@ module Gitlab
] ]
end end
def send_git_patch(repository, from, to) def send_git_patch(repository, diff_refs)
params = { params = {
'RepoPath' => repository.path_to_repo, 'RepoPath' => repository.path_to_repo,
'ShaFrom' => from, 'ShaFrom' => diff_refs.start_sha,
'ShaTo' => to 'ShaTo' => diff_refs.head_sha
} }
[ [
......
...@@ -103,7 +103,7 @@ describe Projects::MergeRequestsController do ...@@ -103,7 +103,7 @@ describe Projects::MergeRequestsController do
id: merge_request.iid, id: merge_request.iid,
format: :patch) format: :patch)
expect(response.headers['Gitlab-Workhorse-Send-Data']).to start_with("git-format-patch:") expect(response.headers[Gitlab::Workhorse::SEND_DATA_HEADER]).to start_with("git-format-patch:")
end end
end 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