Commit 37407132 authored by Nick Thomas's avatar Nick Thomas

Fix the merge request view when source projects or branches are removed

parent e6f515ec
...@@ -554,7 +554,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -554,7 +554,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def define_pipelines_vars def define_pipelines_vars
@pipelines = @merge_request.all_pipelines @pipelines = @merge_request.all_pipelines
if @pipelines.any? if @pipelines.present?
@pipeline = @pipelines.first @pipeline = @pipelines.first
@statuses = @pipeline.statuses.relevant @statuses = @pipeline.statuses.relevant
end end
......
...@@ -86,11 +86,15 @@ module MergeRequestsHelper ...@@ -86,11 +86,15 @@ module MergeRequestsHelper
end end
def source_branch_with_namespace(merge_request) def source_branch_with_namespace(merge_request)
branch = link_to(merge_request.source_branch, namespace_project_commits_path(merge_request.source_project.namespace, merge_request.source_project, merge_request.source_branch)) namespace = merge_request.source_project_namespace
branch = merge_request.source_branch
if merge_request.source_branch_exists?
namespace = link_to(namespace, project_path(merge_request.source_project))
branch = link_to(branch, namespace_project_commits_path(merge_request.source_project.namespace, merge_request.source_project, merge_request.source_branch))
end
if merge_request.for_fork? if merge_request.for_fork?
namespace = link_to(merge_request.source_project_namespace,
project_path(merge_request.source_project))
namespace + ":" + branch namespace + ":" + branch
else else
branch branch
......
...@@ -333,7 +333,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -333,7 +333,7 @@ class MergeRequest < ActiveRecord::Base
end end
def closed_without_fork? def closed_without_fork?
closed? && (forked_source_project_missing? || !source_project) closed? && forked_source_project_missing?
end end
def forked_source_project_missing? def forked_source_project_missing?
...@@ -344,7 +344,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -344,7 +344,7 @@ class MergeRequest < ActiveRecord::Base
end end
def reopenable? def reopenable?
source_branch_exists? && closed? closed? && !source_project_missing? && source_branch_exists?
end end
def ensure_merge_request_diff def ensure_merge_request_diff
...@@ -656,7 +656,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -656,7 +656,7 @@ class MergeRequest < ActiveRecord::Base
end end
def has_ci? def has_ci?
source_project.ci_service && commits.any? source_project.try(:ci_service) && commits.any?
end end
def branch_missing? def branch_missing?
...@@ -688,12 +688,9 @@ class MergeRequest < ActiveRecord::Base ...@@ -688,12 +688,9 @@ class MergeRequest < ActiveRecord::Base
@environments ||= @environments ||=
begin begin
environments = source_project.environments_for( envs = target_project.environments_for(target_branch, diff_head_commit, with_tags: true)
source_branch, diff_head_commit) envs.concat(source_project.environments_for(source_branch, diff_head_commit)) if source_project
environments += target_project.environments_for( envs.uniq
target_branch, diff_head_commit, with_tags: true)
environments.uniq
end end
end end
......
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
- if @merge_request.open? && @merge_request.diverged_from_target_branch? - if @merge_request.open? && @merge_request.diverged_from_target_branch?
%span (#{pluralize(@merge_request.diverged_commits_count, 'commit')} behind) %span (#{pluralize(@merge_request.diverged_commits_count, 'commit')} behind)
- if @merge_request.source_branch_exists?
= render "projects/merge_requests/show/how_to_merge" = render "projects/merge_requests/show/how_to_merge"
= render "projects/merge_requests/widget/show.html.haml" = render "projects/merge_requests/widget/show.html.haml"
- if @merge_request.source_branch_exists? && @merge_request.mergeable? && @merge_request.can_be_merged_by?(current_user) - if @merge_request.source_branch_exists? && @merge_request.mergeable? && @merge_request.can_be_merged_by?(current_user)
...@@ -50,6 +52,7 @@ ...@@ -50,6 +52,7 @@
= link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#notes', action: 'notes', toggle: 'tab' } do = link_to namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#notes', action: 'notes', toggle: 'tab' } do
Discussion Discussion
%span.badge= @merge_request.mr_and_commit_notes.user.count %span.badge= @merge_request.mr_and_commit_notes.user.count
- if @merge_request.source_project
%li.commits-tab %li.commits-tab
= link_to commits_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#commits', action: 'commits', toggle: 'tab' } do = link_to commits_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), data: { target: 'div#commits', action: 'commits', toggle: 'tab' } do
Commits Commits
......
...@@ -25,6 +25,20 @@ feature 'Merge request created from fork' do ...@@ -25,6 +25,20 @@ feature 'Merge request created from fork' do
expect(page).to have_content 'Test merge request' expect(page).to have_content 'Test merge request'
end end
context 'source project is deleted' do
background do
MergeRequests::MergeService.new(project, user).execute(merge_request)
fork_project.destroy!
end
scenario 'user can access merge request' do
visit_merge_request(merge_request)
expect(page).to have_content 'Test merge request'
expect(page).to have_content "(removed):#{merge_request.source_branch}"
end
end
context 'pipeline present in source project' do context 'pipeline present in source project' do
include WaitForAjax include WaitForAjax
......
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