Class: Gitlab::Git::Conflict::Resolver

Inherits:
Object
  • Object
show all
Includes:
WrapsGitalyErrors
Defined in:
lib/gitlab/git/conflict/resolver.rb

Constant Summary collapse

ConflictSideMissing =
Class.new(StandardError)
ResolutionError =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from WrapsGitalyErrors

#wrapped_gitaly_errors

Constructor Details

#initialize(target_repository, our_commit_oid, their_commit_oid, allow_tree_conflicts: false, skip_content: false) ⇒ Resolver

Returns a new instance of Resolver.



12
13
14
15
16
17
18
# File 'lib/gitlab/git/conflict/resolver.rb', line 12

def initialize(target_repository, our_commit_oid, their_commit_oid, allow_tree_conflicts: false, skip_content: false)
  @target_repository = target_repository
  @our_commit_oid = our_commit_oid
  @their_commit_oid = their_commit_oid
  @allow_tree_conflicts = allow_tree_conflicts
  @skip_content = skip_content
end

Instance Method Details

#conflict_for_path(conflicts, old_path, new_path) ⇒ Object



41
42
43
44
45
# File 'lib/gitlab/git/conflict/resolver.rb', line 41

def conflict_for_path(conflicts, old_path, new_path)
  conflicts.find do |conflict|
    conflict.their_path == old_path && conflict.our_path == new_path
  end
end

#conflictsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/git/conflict/resolver.rb', line 20

def conflicts
  @conflicts ||= wrapped_gitaly_errors do
    gitaly_conflicts_client(@target_repository)
      .list_conflict_files(
        allow_tree_conflicts: @allow_tree_conflicts,
        skip_content: @skip_content
      )
      .to_a
  rescue GRPC::FailedPrecondition => e
    raise Gitlab::Git::Conflict::Resolver::ConflictSideMissing, e.message
  end
rescue GRPC::BadStatus => e
  raise Gitlab::Git::CommandError, e
end

#resolve_conflicts(source_repository, resolution, source_branch:, target_branch:) ⇒ Object



35
36
37
38
39
# File 'lib/gitlab/git/conflict/resolver.rb', line 35

def resolve_conflicts(source_repository, resolution, source_branch:, target_branch:)
  wrapped_gitaly_errors do
    gitaly_conflicts_client(source_repository).resolve_conflicts(@target_repository, resolution, source_branch, target_branch)
  end
end