diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-15 15:27:14 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-07-15 15:27:14 +0200 |
commit | 277f311f20739bd97f4059b51dfa1dbc38aa38e1 (patch) | |
tree | eeaacaf966b4fc5c27b2887bb0bbc0c76cd94e6b | |
parent | 997a3b1d872f6b6b198582677acd67595bb15029 (diff) | |
download | gitlab-ce-277f311f20739bd97f4059b51dfa1dbc38aa38e1.tar.gz |
Fetch reference from fork repo when create merge request
-rw-r--r-- | app/models/repository.rb | 5 | ||||
-rw-r--r-- | app/services/merge_requests/create_service.rb | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index 6262b5c4c92..70d416159a7 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -465,6 +465,11 @@ class Repository ) 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 def cache diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb index f431c5d5534..8389f29a53a 100644 --- a/app/services/merge_requests/create_service.rb +++ b/app/services/merge_requests/create_service.rb @@ -9,6 +9,15 @@ module MergeRequests merge_request.author = current_user 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) event_service.open_mr(merge_request, current_user) notification_service.new_merge_request(merge_request, current_user) |