summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/merge_requests_controller.rb4
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb12
3 files changed, 17 insertions, 1 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index d521db79f85..9781d159540 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -122,6 +122,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
respond_to do |format|
format.html do
+ if merge_request_params[:state_event] && @merge_request.errors.any?
+ flash[:alert] = @merge_request.errors.values.flatten.to_sentence
+ end
+
if @merge_request.valid?
redirect_to([@merge_request.target_project.namespace.becomes(Namespace), @merge_request.target_project, @merge_request])
else
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index d0811a715bc..b50cfa639e0 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -547,7 +547,7 @@ class MergeRequest < ActiveRecord::Base
similar_mrs = similar_mrs.where('id not in (?)', self.id) if self.id
if similar_mrs.any?
errors.add :validate_branches,
- "Cannot Create: This merge request already exists: #{similar_mrs.pluck(:title)}"
+ "Cannot open this Merge Request because another open Merge Request already exists for this source branch: #{similar_mrs.first.title}"
end
end
end
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index e62523c65c9..9e8ec99e314 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -290,6 +290,18 @@ describe Projects::MergeRequestsController do
it_behaves_like 'update invalid issuable', MergeRequest
end
+
+ context 'there are two merge requests with the same source branch' do
+ it "does not allow to reopen a closed merge request if another one is open" do
+ merge_request.close!
+ create(:merge_request, source_project: merge_request.source_project, source_branch: merge_request.source_branch)
+
+ update_merge_request(state_event: 'reopen')
+
+ expect(controller).to set_flash[:alert].to(/another open Merge Request already exists for this source branch/)
+ expect(merge_request.reload).to be_closed
+ end
+ end
end
describe 'POST merge' do