2016-07-27 11:42:18 +00:00
|
|
|
module Gitlab
|
|
|
|
module Conflict
|
|
|
|
class FileCollection
|
2017-10-09 19:40:37 +00:00
|
|
|
attr_reader :merge_request, :resolver
|
2017-10-07 01:41:23 +00:00
|
|
|
|
|
|
|
def initialize(merge_request)
|
|
|
|
source_repo = merge_request.source_project.repository.raw
|
|
|
|
our_commit = merge_request.source_branch_head.raw
|
|
|
|
their_commit = merge_request.target_branch_head.raw
|
|
|
|
target_repo = merge_request.target_project.repository.raw
|
2017-10-09 19:40:37 +00:00
|
|
|
@resolver = Gitlab::Git::Conflict::Resolver.new(source_repo, our_commit, target_repo, their_commit)
|
2017-10-07 01:41:23 +00:00
|
|
|
@merge_request = merge_request
|
2017-10-05 23:22:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolve(user, commit_message, files)
|
2017-10-07 01:41:23 +00:00
|
|
|
args = {
|
|
|
|
source_branch: merge_request.source_branch,
|
|
|
|
target_branch: merge_request.target_branch,
|
|
|
|
commit_message: commit_message || default_commit_message
|
|
|
|
}
|
2017-10-09 19:40:37 +00:00
|
|
|
resolver.resolve_conflicts(user, files, args)
|
2016-07-27 16:54:04 +00:00
|
|
|
end
|
|
|
|
|
2016-07-27 11:42:18 +00:00
|
|
|
def files
|
2017-10-09 19:40:37 +00:00
|
|
|
@files ||= resolver.conflicts.map do |conflict_file|
|
2017-10-07 01:41:23 +00:00
|
|
|
Gitlab::Conflict::File.new(conflict_file, merge_request: merge_request)
|
2016-07-27 11:42:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-01 12:59:10 +00:00
|
|
|
def file_for_path(old_path, new_path)
|
|
|
|
files.find { |file| file.their_path == old_path && file.our_path == new_path }
|
|
|
|
end
|
|
|
|
|
2016-07-27 11:42:18 +00:00
|
|
|
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
|
2017-10-07 01:41:23 +00:00
|
|
|
conflict_filenames = files.map do |conflict|
|
|
|
|
"# #{conflict.our_path}"
|
2016-07-27 11:42:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
<<EOM.chomp
|
2016-08-05 11:15:06 +00:00
|
|
|
Merge branch '#{merge_request.target_branch}' into '#{merge_request.source_branch}'
|
2016-07-27 11:42:18 +00:00
|
|
|
|
|
|
|
# Conflicts:
|
|
|
|
#{conflict_filenames.join("\n")}
|
|
|
|
EOM
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|