From 7c00b53812895970fdb00cf1d27b059bb15815cd Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 21 Sep 2017 18:34:32 +0200 Subject: [PATCH] Find branches in all projects in the fork network --- .../merge_requests/creations_controller.rb | 7 +++++-- .../merge_request_target_project_finder.rb | 2 +- .../create_new_mr_from_fork_spec.rb | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects/merge_requests/creations_controller.rb b/app/controllers/projects/merge_requests/creations_controller.rb index 1096afbb798..99dc3dda9e7 100644 --- a/app/controllers/projects/merge_requests/creations_controller.rb +++ b/app/controllers/projects/merge_requests/creations_controller.rb @@ -120,10 +120,13 @@ class Projects::MergeRequests::CreationsController < Projects::MergeRequests::Ap end def selected_target_project - if @project.id.to_s == params[:target_project_id] || @project.forked_project_link.nil? + if @project.id.to_s == params[:target_project_id] || !@project.forked? @project + elsif params[:target_project_id].present? + MergeRequestTargetProjectFinder.new(current_user: current_user, source_project: @project) + .execute.find(params[:target_project_id]) else - @project.forked_project_link.forked_from_project + @project.forked_from_project end end end diff --git a/app/finders/merge_request_target_project_finder.rb b/app/finders/merge_request_target_project_finder.rb index 508b53a52c1..189eb3847eb 100644 --- a/app/finders/merge_request_target_project_finder.rb +++ b/app/finders/merge_request_target_project_finder.rb @@ -1,7 +1,7 @@ class MergeRequestTargetProjectFinder attr_reader :current_user, :source_project - def initialize(current_user: nil, source_project:, params: {}) + def initialize(current_user: nil, source_project:) @current_user = current_user @source_project = source_project end diff --git a/spec/features/merge_requests/create_new_mr_from_fork_spec.rb b/spec/features/merge_requests/create_new_mr_from_fork_spec.rb index 515818c5d42..e6f827174e2 100644 --- a/spec/features/merge_requests/create_new_mr_from_fork_spec.rb +++ b/spec/features/merge_requests/create_new_mr_from_fork_spec.rb @@ -44,6 +44,25 @@ feature 'Creating a merge request from a fork', :js do expect { click_button 'Submit merge request' } .to change { target_project.merge_requests.reload.size }.by(1) end + + it 'updates the branches when selecting a new target project' do + target_project_member = target_project.owner + CreateBranchService.new(target_project, target_project_member) + .execute('a-brand-new-branch-to-test', 'master') + + visit project_new_merge_request_path(source_project) + + first('.js-target-project').click + find('.dropdown-target-project .dropdown-content a', text: target_project.full_path).click + + wait_for_requests + + first('.js-target-branch').click + + within('.dropdown-target-branch .dropdown-content') do + expect(page).to have_content('a-brand-new-branch-to-test') + end + end end context 'creating to the source of a fork' do