Commit b244be6c authored by Thibault's avatar Thibault Committed by Igor Drozdov

Check source project is existing before editing merge request

parent c9d043c6
...@@ -946,7 +946,8 @@ class MergeRequest < ApplicationRecord ...@@ -946,7 +946,8 @@ class MergeRequest < ApplicationRecord
end end
def can_remove_source_branch?(current_user) def can_remove_source_branch?(current_user)
!ProtectedBranch.protected?(source_project, source_branch) && source_project &&
!ProtectedBranch.protected?(source_project, source_branch) &&
!source_project.root_ref?(source_branch) && !source_project.root_ref?(source_branch) &&
Ability.allowed?(current_user, :push_code, source_project) && Ability.allowed?(current_user, :push_code, source_project) &&
diff_head_sha == source_branch_head.try(:sha) diff_head_sha == source_branch_head.try(:sha)
......
...@@ -1170,6 +1170,12 @@ describe MergeRequest do ...@@ -1170,6 +1170,12 @@ describe MergeRequest do
expect(subject.can_remove_source_branch?(user)).to be_falsey expect(subject.can_remove_source_branch?(user)).to be_falsey
end end
it "can't be removed because source project has been deleted" do
subject.source_project = nil
expect(subject.can_remove_source_branch?(user)).to be_falsey
end
it "can't remove a root ref" do it "can't remove a root ref" do
subject.update(source_branch: 'master', target_branch: 'feature') subject.update(source_branch: 'master', target_branch: 'feature')
......
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