Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2016-07-27 14:42:18 +0300
committerFatih Acet <acetfatih@gmail.com>2016-08-12 23:24:43 +0300
commita1c79612172ce07c7b0de4c01fba8fa7369c71de (patch)
treefb8ad8e663fe2d30f43a2b0453d66fda6ce05301 /lib/gitlab/conflict
parentdf2ed097b730c8ba0b79cac8cc3dbfcb0cf587cb (diff)
Handle multiple merge conflict files in collection
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r--lib/gitlab/conflict/file.rb18
-rw-r--r--lib/gitlab/conflict/file_collection.rb59
-rw-r--r--lib/gitlab/conflict/parser.rb8
3 files changed, 71 insertions, 14 deletions
diff --git a/lib/gitlab/conflict/file.rb b/lib/gitlab/conflict/file.rb
index 84d3e6f4e03..7f81c72431d 100644
--- a/lib/gitlab/conflict/file.rb
+++ b/lib/gitlab/conflict/file.rb
@@ -3,20 +3,22 @@ module Gitlab
class File
CONTEXT_LINES = 3
- attr_reader :merge_file, :their_path, :their_ref, :our_path, :our_ref, :repository
+ attr_reader :merge_file_result, :their_path, :their_ref, :our_path, :our_ref, :repository
- def initialize(merge_file, conflict, their_ref, our_ref, repository)
- @merge_file = merge_file
+ def initialize(merge_file_result, conflict, diff_refs:, repository:)
+ @merge_file_result = merge_file_result
@their_path = conflict[:theirs][:path]
@our_path = conflict[:ours][:path]
- @their_ref = their_ref
- @our_ref = our_ref
+ @their_ref = diff_refs.start_sha
+ @our_ref = diff_refs.head_sha
@repository = repository
end
# Array of Gitlab::Diff::Line objects
def lines
- @lines ||= Gitlab::Conflict::Parser.new.parse(merge_file[:data], their_path, our_path)
+ @lines ||= Gitlab::Conflict::Parser.new.parse(merge_file_result[:data],
+ our_path: our_path,
+ their_path: their_path)
end
def highlighted_lines
@@ -28,9 +30,9 @@ module Gitlab
@highlighted_lines = lines.map do |line|
line = line.dup
if line.type == 'old'
- line.rich_text = their_highlight[line.old_line - 1].delete("\n")
+ line.rich_text = their_highlight[line.old_line - 1]
else
- line.rich_text = our_highlight[line.new_line - 1].delete("\n")
+ line.rich_text = our_highlight[line.new_line - 1]
end
line
end
diff --git a/lib/gitlab/conflict/file_collection.rb b/lib/gitlab/conflict/file_collection.rb
new file mode 100644
index 00000000000..a3035a5c3e6
--- /dev/null
+++ b/lib/gitlab/conflict/file_collection.rb
@@ -0,0 +1,59 @@
+module Gitlab
+ module Conflict
+ class FileCollection
+ attr_reader :merge_request, :our_commit, :their_commit
+
+ def initialize(merge_request)
+ @merge_request = merge_request
+ @our_commit = merge_request.diff_head_commit.raw.raw_commit
+ @their_commit = merge_request.target_branch_head.raw.raw_commit
+ end
+
+ def repository
+ merge_request.project.repository
+ end
+
+ def merge_index
+ @merge_index ||= repository.rugged.merge_commits(our_commit, their_commit)
+ end
+
+ def files
+ @files ||= merge_index.conflicts.map do |conflict|
+ their_path = conflict[:theirs][:path]
+ our_path = conflict[:ours][:path]
+
+ # TODO remove this
+ raise 'path mismatch!' unless their_path == our_path
+
+ Gitlab::Conflict::File.new(merge_index.merge_file(our_path),
+ conflict,
+ diff_refs: merge_request.diff_refs,
+ repository: repository)
+ end
+ end
+
+ def as_json(opts = nil)
+ {
+ target_branch: merge_request.target_branch,
+ source_branch: merge_request.source_branch,
+ commit_sha: merge_request.diff_head_sha,
+ commit_message: default_commit_message,
+ files: files
+ }
+ end
+
+ def default_commit_message
+ conflict_filenames = merge_index.conflicts.map do |conflict|
+ "# #{conflict[:ours][:path]}"
+ end
+
+ <<EOM.chomp
+Merge branch '#{merge_request.source_branch}' into '#{merge_request.target_branch}'
+
+# Conflicts:
+#{conflict_filenames.join("\n")}
+EOM
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/conflict/parser.rb b/lib/gitlab/conflict/parser.rb
index a233c268070..9c541931680 100644
--- a/lib/gitlab/conflict/parser.rb
+++ b/lib/gitlab/conflict/parser.rb
@@ -7,7 +7,7 @@ module Gitlab
class MissingEndDelimiter < StandardError
end
- def parse(text, their_path, our_path)
+ def parse(text, our_path:, their_path:)
return [] if text.blank?
line_obj_index = 0
@@ -46,14 +46,10 @@ module Gitlab
end
end
- raise MissingEndDelimiter unless type == nil
+ raise MissingEndDelimiter unless type.nil?
lines
end
-
- def empty?
- @lines.empty?
- end
end
end
end