Commit 5fd5dad4 authored by Akos Gyimesi's avatar Akos Gyimesi Committed by Nick Thomas

Improve error message when attempting to reopen MR and there's a new open MR for the same branch

parent 2e3cefa6
......@@ -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
......
......@@ -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
......
......@@ -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
......
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