Commit 277f311f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fetch reference from fork repo when create merge request

parent 997a3b1d
...@@ -465,6 +465,11 @@ class Repository ...@@ -465,6 +465,11 @@ class Repository
) )
end end
def fetch_ref(source_path, source_ref, target_ref)
args = %W(git fetch #{source_path} #{source_ref}:#{target_ref})
Gitlab::Popen.popen(args, path_to_repo)
end
private private
def cache def cache
......
...@@ -9,6 +9,15 @@ module MergeRequests ...@@ -9,6 +9,15 @@ module MergeRequests
merge_request.author = current_user merge_request.author = current_user
if merge_request.save if merge_request.save
# Fetch fork branch into hidden ref of target repository
if merge_request.for_fork?
merge_request.target_project.repository.fetch_ref(
merge_request.source_project.repository.path_to_repo,
"refs/heads/#{merge_request.source_branch}",
"refs/merge-requests/#{merge_request.id}/head"
)
end
merge_request.update_attributes(label_ids: label_params) merge_request.update_attributes(label_ids: label_params)
event_service.open_mr(merge_request, current_user) event_service.open_mr(merge_request, current_user)
notification_service.new_merge_request(merge_request, current_user) notification_service.new_merge_request(merge_request, current_user)
......
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