2017-10-09 15:40:37 -04:00
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
module Conflict
|
|
|
|
class Resolver
|
|
|
|
ConflictSideMissing = Class.new(StandardError)
|
|
|
|
ResolutionError = Class.new(StandardError)
|
|
|
|
|
2017-12-12 20:55:30 -05:00
|
|
|
def initialize(target_repository, our_commit_oid, their_commit_oid)
|
2017-10-09 15:40:37 -04:00
|
|
|
@target_repository = target_repository
|
2017-12-12 20:55:30 -05:00
|
|
|
@our_commit_oid = our_commit_oid
|
|
|
|
@their_commit_oid = their_commit_oid
|
2017-10-09 15:40:37 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def conflicts
|
2018-07-06 05:42:15 -04:00
|
|
|
@conflicts ||= @target_repository.wrapped_gitaly_errors do
|
|
|
|
gitaly_conflicts_client(@target_repository).list_conflict_files.to_a
|
2017-10-09 15:40:37 -04:00
|
|
|
end
|
2017-12-05 14:42:04 -05:00
|
|
|
rescue GRPC::FailedPrecondition => e
|
|
|
|
raise Gitlab::Git::Conflict::Resolver::ConflictSideMissing.new(e.message)
|
2018-07-27 04:43:19 -04:00
|
|
|
rescue GRPC::BadStatus => e
|
2017-12-05 14:42:04 -05:00
|
|
|
raise Gitlab::Git::CommandError.new(e)
|
2017-10-09 15:40:37 -04:00
|
|
|
end
|
|
|
|
|
2017-12-27 14:49:05 -05:00
|
|
|
def resolve_conflicts(source_repository, resolution, source_branch:, target_branch:)
|
2018-07-06 05:42:15 -04:00
|
|
|
source_repository.wrapped_gitaly_errors do
|
|
|
|
gitaly_conflicts_client(source_repository).resolve_conflicts(@target_repository, resolution, source_branch, target_branch)
|
2017-10-09 15:40:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-12 20:55:30 -05:00
|
|
|
def conflict_for_path(conflicts, old_path, new_path)
|
2017-10-09 15:40:37 -04:00
|
|
|
conflicts.find do |conflict|
|
|
|
|
conflict.their_path == old_path && conflict.our_path == new_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-12-12 20:55:30 -05:00
|
|
|
def conflict_files(repository, index)
|
|
|
|
index.conflicts.map do |conflict|
|
|
|
|
raise ConflictSideMissing unless conflict[:theirs] && conflict[:ours]
|
|
|
|
|
|
|
|
Gitlab::Git::Conflict::File.new(
|
|
|
|
repository,
|
|
|
|
@our_commit_oid,
|
|
|
|
conflict,
|
|
|
|
index.merge_file(conflict[:ours][:path])[:data]
|
|
|
|
)
|
|
|
|
end
|
2017-10-09 15:40:37 -04:00
|
|
|
end
|
|
|
|
|
2017-12-05 17:18:20 -05:00
|
|
|
def gitaly_conflicts_client(repository)
|
|
|
|
repository.gitaly_conflicts_client(@our_commit_oid, @their_commit_oid)
|
|
|
|
end
|
2017-10-09 15:40:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|