From 1fcf3f3d94a157e2b57735ca9d0a306b91e75323 Mon Sep 17 00:00:00 2001
From: Shinya Maeda <shinya@gitlab.com>
Date: Wed, 2 Aug 2017 22:11:32 +0900
Subject: [PATCH] essential

---
 app/services/merge_requests/create_service.rb | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/app/services/merge_requests/create_service.rb b/app/services/merge_requests/create_service.rb
index 19189e64acf..5414fa79def 100644
--- a/app/services/merge_requests/create_service.rb
+++ b/app/services/merge_requests/create_service.rb
@@ -12,7 +12,6 @@ module MergeRequests
       merge_request.source_project = source_project
       merge_request.source_branch = params[:source_branch]
       merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch)
-      merge_request.head_pipeline = head_pipeline_for(merge_request)
 
       create(merge_request)
     end
@@ -22,10 +21,16 @@ module MergeRequests
       notification_service.new_merge_request(issuable, current_user)
       todo_service.new_merge_request(issuable, current_user)
       issuable.cache_merge_request_closes_issues!(current_user)
+      update_merge_requests_head_pipeline(issuable)
     end
 
     private
 
+    def update_merge_requests_head_pipeline(merge_request)
+      pipeline = head_pipeline_for(merge_request)
+      merge_request.update(head_pipeline_id: pipeline.id) if pipeline
+    end
+
     def head_pipeline_for(merge_request)
       return unless merge_request.source_project
 
-- 
GitLab