Commit 9439cb55 authored by Jacob Carlborg's avatar Jacob Carlborg Committed by Jacob Carlborg

By default, target original repository if fork when creating new MR.

parent 504777ec
...@@ -60,7 +60,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -60,7 +60,11 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def new def new
@merge_request = MergeRequest.new(params[:merge_request]) @merge_request = MergeRequest.new(params[:merge_request])
@merge_request.source_project = @project unless @merge_request.source_project @merge_request.source_project = @project unless @merge_request.source_project
@merge_request.target_project = @project unless @merge_request.target_project @merge_request.target_project ||= (@project.forked_from_project || @project)
@target_branches = @merge_request.target_project.nil? ? [] : @merge_request.target_project.repository.branch_names
@merge_request.target_branch ||= @merge_request.target_project.default_branch
@source_project = @merge_request.source_project @source_project = @merge_request.source_project
@merge_request @merge_request
end end
......
module MergeRequestsHelper module MergeRequestsHelper
def new_mr_path_from_push_event(event) def new_mr_path_from_push_event(event)
target_project = event.project.forked_from_project || event.project
new_project_merge_request_path( new_project_merge_request_path(
event.project, event.project,
new_mr_from_push_event(event, event.project) new_mr_from_push_event(event, target_project)
) )
end end
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
.clearfix .clearfix
.pull-left .pull-left
- projects = @project.forked_from_project.nil? ? [@project] : [ @project,@project.forked_from_project] - projects = @project.forked_from_project.nil? ? [@project] : [ @project,@project.forked_from_project]
= f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace'), {}, { class: 'target_project select2 span3', disabled: @merge_request.persisted? }) = f.select(:target_project_id, options_from_collection_for_select(projects, 'id', 'path_with_namespace', f.object.target_project_id), {}, { class: 'target_project select2 span3', disabled: @merge_request.persisted? })
.pull-left .pull-left
&nbsp; &nbsp;
= f.select(:target_branch, @merge_request.target_branches, { include_blank: "Select branch" }, {class: 'target_branch select2 span2'}) = f.select(:target_branch, @merge_request.target_branches, { include_blank: "Select branch" }, {class: 'target_branch select2 span2'})
......
...@@ -32,3 +32,9 @@ Feature: Project Forked Merge Requests ...@@ -32,3 +32,9 @@ Feature: Project Forked Merge Requests
And I fill out an invalid "Merge Request On Forked Project" merge request And I fill out an invalid "Merge Request On Forked Project" merge request
And I submit the merge request And I submit the merge request
Then I should see validation errors Then I should see validation errors
@javascript
Scenario: Merge request should target fork repository by default
Given I visit project "Forked Shop" merge requests page
And I click link "New Merge Request"
Then the target repository should be the original repository
\ No newline at end of file
...@@ -159,8 +159,11 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps ...@@ -159,8 +159,11 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
step 'I fill out an invalid "Merge Request On Forked Project" merge request' do step 'I fill out an invalid "Merge Request On Forked Project" merge request' do
#If this isn't filled in the rest of the validations won't be triggered #If this isn't filled in the rest of the validations won't be triggered
fill_in "merge_request_title", with: "Merge Request On Forked Project" fill_in "merge_request_title", with: "Merge Request On Forked Project"
select "Select branch", from: "merge_request_target_branch"
find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s find(:select, "merge_request_source_project_id", {}).value.should == @forked_project.id.to_s
find(:select, "merge_request_target_project_id", {}).value.should == @forked_project.id.to_s find(:select, "merge_request_target_project_id", {}).value.should == project.id.to_s
find(:select, "merge_request_source_branch", {}).value.should == "" find(:select, "merge_request_source_branch", {}).value.should == ""
find(:select, "merge_request_target_branch", {}).value.should == "" find(:select, "merge_request_target_branch", {}).value.should == ""
end end
...@@ -168,7 +171,10 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps ...@@ -168,7 +171,10 @@ class ProjectForkedMergeRequests < Spinach::FeatureSteps
step 'I should see validation errors' do step 'I should see validation errors' do
page.should have_content "Source branch can't be blank" page.should have_content "Source branch can't be blank"
page.should have_content "Target branch can't be blank" page.should have_content "Target branch can't be blank"
page.should have_content "Branch conflict You can not use same project/branch for source and target" end
step 'the target repository should be the original repository' do
page.should have_select("merge_request_target_project_id", selected: project.path_with_namespace)
end end
def project def project
......
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