From f3cf40b8aaeb19479443821a767c354cd203c24e Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Mon, 1 Aug 2016 14:52:53 +0100 Subject: [PATCH] Handle case where one side deleted the file --- app/controllers/projects/merge_requests_controller.rb | 2 +- lib/gitlab/conflict/file_collection.rb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index e34f4d102ce..13eb5fb2ffb 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -140,7 +140,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController format.json do begin render json: Gitlab::Conflict::FileCollection.new(@merge_request) - rescue Gitlab::Conflict::Parser::ParserError => e + rescue Gitlab::Conflict::Parser::ParserError, Gitlab::Conflict::FileCollection::ConflictSideMissing => e render json: { message: 'Unable to resolve conflicts in the web interface for this merge request' } end end diff --git a/lib/gitlab/conflict/file_collection.rb b/lib/gitlab/conflict/file_collection.rb index e621a76a7de..5122a5b2111 100644 --- a/lib/gitlab/conflict/file_collection.rb +++ b/lib/gitlab/conflict/file_collection.rb @@ -1,6 +1,9 @@ module Gitlab module Conflict class FileCollection + class ConflictSideMissing < StandardError + end + attr_reader :merge_request, :our_commit, :their_commit def initialize(merge_request) @@ -39,10 +42,9 @@ module Gitlab def files @files ||= merge_index.conflicts.map do |conflict| - their_path = conflict[:theirs][:path] - our_path = conflict[:ours][:path] + raise ConflictSideMissing unless conflict[:theirs] && conflict[:ours] - Gitlab::Conflict::File.new(merge_index.merge_file(our_path), + Gitlab::Conflict::File.new(merge_index.merge_file(conflict[:ours][:path]), conflict, diff_refs: merge_request.diff_refs, repository: repository)