Commit 954c45ab authored by Jonas Hahnfeld's avatar Jonas Hahnfeld

Ignore missing source project when editing MR

Also hide the branch chooser if the branch has been merged, not only
when the MR was closed.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/218228
parent bb9ef246
...@@ -83,7 +83,7 @@ module MergeRequestsHelper ...@@ -83,7 +83,7 @@ module MergeRequestsHelper
end end
def merge_request_button_hidden?(merge_request, closed) def merge_request_button_hidden?(merge_request, closed)
merge_request.closed? == closed || (merge_request.merged? == closed && !merge_request.closed?) || merge_request.closed_without_fork? merge_request.closed? == closed || (merge_request.merged? == closed && !merge_request.closed?) || merge_request.closed_or_merged_without_fork?
end end
def merge_request_version_path(project, merge_request, merge_request_diff, start_sha = nil) def merge_request_version_path(project, merge_request, merge_request_diff, start_sha = nil)
......
...@@ -233,13 +233,13 @@ class MergeRequest < ApplicationRecord ...@@ -233,13 +233,13 @@ class MergeRequest < ApplicationRecord
cannot_be_merged_rechecking? ? 'checking' : merge_status cannot_be_merged_rechecking? ? 'checking' : merge_status
end end
validates :source_project, presence: true, unless: [:allow_broken, :importing?, :closed_without_fork?] validates :source_project, presence: true, unless: [:allow_broken, :importing?, :closed_or_merged_without_fork?]
validates :source_branch, presence: true validates :source_branch, presence: true
validates :target_project, presence: true validates :target_project, presence: true
validates :target_branch, presence: true validates :target_branch, presence: true
validates :merge_user, presence: true, if: :auto_merge_enabled?, unless: :importing? validates :merge_user, presence: true, if: :auto_merge_enabled?, unless: :importing?
validate :validate_branches, unless: [:allow_broken, :importing?, :closed_without_fork?] validate :validate_branches, unless: [:allow_broken, :importing?, :closed_or_merged_without_fork?]
validate :validate_fork, unless: :closed_without_fork? validate :validate_fork, unless: :closed_or_merged_without_fork?
validate :validate_target_project, on: :create validate :validate_target_project, on: :create
scope :by_source_or_target_branch, ->(branch_name) do scope :by_source_or_target_branch, ->(branch_name) do
...@@ -883,8 +883,8 @@ class MergeRequest < ApplicationRecord ...@@ -883,8 +883,8 @@ class MergeRequest < ApplicationRecord
!!merge_jid && !merged? && Gitlab::SidekiqStatus.running?(merge_jid) !!merge_jid && !merged? && Gitlab::SidekiqStatus.running?(merge_jid)
end end
def closed_without_fork? def closed_or_merged_without_fork?
closed? && source_project_missing? (closed? || merged?) && source_project_missing?
end end
def source_project_missing? def source_project_missing?
......
...@@ -11,7 +11,7 @@ module MergeRequests ...@@ -11,7 +11,7 @@ module MergeRequests
params.delete(:target_project_id) params.delete(:target_project_id)
params.delete(:source_branch) params.delete(:source_branch)
if merge_request.closed_without_fork? if merge_request.closed_or_merged_without_fork?
params.delete(:target_branch) params.delete(:target_branch)
params.delete(:force_remove_source_branch) params.delete(:force_remove_source_branch)
end end
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- state_human_name, state_icon_name = state_name_with_icon(@merge_request) - state_human_name, state_icon_name = state_name_with_icon(@merge_request)
- are_close_and_open_buttons_hidden = merge_request_button_hidden?(@merge_request, true) && merge_request_button_hidden?(@merge_request, false) - are_close_and_open_buttons_hidden = merge_request_button_hidden?(@merge_request, true) && merge_request_button_hidden?(@merge_request, false)
- if @merge_request.closed_without_fork? - if @merge_request.closed_or_merged_without_fork?
.gl-alert.gl-alert-danger.gl-mb-5 .gl-alert.gl-alert-danger.gl-mb-5
= sprite_icon('error', size: 16, css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title') = sprite_icon('error', size: 16, css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title')
.gl-alert-body .gl-alert-body
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- form = local_assigns.fetch(:form) - form = local_assigns.fetch(:form)
- return unless issuable.is_a?(MergeRequest) - return unless issuable.is_a?(MergeRequest)
- return if issuable.closed_without_fork? - return if issuable.closed_or_merged_without_fork?
- source_title, target_title = format_mr_branch_names(@merge_request) - source_title, target_title = format_mr_branch_names(@merge_request)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
- project = local_assigns.fetch(:project) - project = local_assigns.fetch(:project)
- return unless issuable.is_a?(MergeRequest) - return unless issuable.is_a?(MergeRequest)
- return if issuable.closed_without_fork? - return if issuable.closed_or_merged_without_fork?
.form-group.row .form-group.row
.col-sm-2.col-form-label.pt-sm-0 .col-sm-2.col-form-label.pt-sm-0
......
...@@ -3370,7 +3370,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -3370,7 +3370,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
end end
end end
describe "#closed_without_fork?" do describe "#closed_or_merged_without_fork?" do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:forked_project) { fork_project(project) } let(:forked_project) { fork_project(project) }
let(:user) { create(:user) } let(:user) { create(:user) }
...@@ -3384,14 +3384,33 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -3384,14 +3384,33 @@ RSpec.describe MergeRequest, factory_default: :keep do
end end
it "returns false if the fork exist" do it "returns false if the fork exist" do
expect(closed_merge_request.closed_without_fork?).to be_falsey expect(closed_merge_request.closed_or_merged_without_fork?).to be_falsey
end end
it "returns true if the fork does not exist" do it "returns true if the fork does not exist" do
unlink_project.execute unlink_project.execute
closed_merge_request.reload closed_merge_request.reload
expect(closed_merge_request.closed_without_fork?).to be_truthy expect(closed_merge_request.closed_or_merged_without_fork?).to be_truthy
end
end
context "when the merge request was merged" do
let(:merged_merge_request) do
create(:merged_merge_request,
source_project: forked_project,
target_project: project)
end
it "returns false if the fork exist" do
expect(merged_merge_request.closed_or_merged_without_fork?).to be_falsey
end
it "returns true if the fork does not exist" do
unlink_project.execute
merged_merge_request.reload
expect(merged_merge_request.closed_or_merged_without_fork?).to be_truthy
end end
end end
...@@ -3403,7 +3422,7 @@ RSpec.describe MergeRequest, factory_default: :keep do ...@@ -3403,7 +3422,7 @@ RSpec.describe MergeRequest, factory_default: :keep do
end end
it "returns false" do it "returns false" do
expect(open_merge_request.closed_without_fork?).to be_falsey expect(open_merge_request.closed_or_merged_without_fork?).to be_falsey
end end
end end
end end
......
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