Commit 207bc8a0 authored by Marin Jankovski's avatar Marin Jankovski

Branches without parent commit cannot be merged.

parent 25c9bf4b
......@@ -95,6 +95,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@note_counts = Note.where(commit_id: @commits.map(&:id)).
group(:commit_id).count
begin
@diffs = compare_action.diffs
@merge_request.title = @merge_request.source_branch.titleize.humanize
@target_project = @merge_request.target_project
......@@ -103,6 +104,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
diff_line_count = Commit::diff_line_count(@diffs)
@suppress_diff = Commit::diff_suppress?(@diffs, diff_line_count)
@force_suppress_diff = @suppress_diff
rescue Gitlab::Satellite::BranchesWithoutParent
@error = "Selected branches have no common commit so they cannot be compared."
end
end
end
......
......@@ -10,8 +10,11 @@
%span.pull-right
= link_to 'Change branches', new_project_merge_request_path(@project)
= form_for [@project, @merge_request], html: { class: "merge-request-form" } do |f|
- if @error.present?
.centered-light-block
%h4 #{@error}
- else
= form_for [@project, @merge_request], html: { class: "merge-request-form" } do |f|
.panel.panel-default
.panel-body
......@@ -56,7 +59,7 @@
= f.hidden_field :source_branch
= f.submit 'Submit merge request', class: "btn btn-create"
.mr-compare
.mr-compare
%div.panel.panel-default
.panel-heading
Commits (#{@commits.count})
......
module Gitlab
module Satellite
class BranchesWithoutParent < StandardError; end
class CompareAction < Action
def initialize(user, target_project, target_branch, source_project, source_branch)
super user, target_project
......@@ -22,7 +24,7 @@ module Gitlab
diffs
end
rescue Grit::Git::CommandFailed => ex
handle_exception(ex)
raise BranchesWithoutParent
end
# Retrieve an array of commits between the source and the target
......
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