org.eclipse.jgit.merge

## Class ResolveMerger

- java.lang.Object
- - org.eclipse.jgit.merge.Merger
  - - org.eclipse.jgit.merge.ThreeWayMerger
    - - org.eclipse.jgit.merge.ResolveMerger

Direct Known Subclasses:
  RecursiveMerger

    public class ResolveMerger
    extends ThreeWayMerger

A three-way merger performing a content-merge if necessary

### Nested Class Summary

Nested Classes
`static class` `ResolveMerger.MergeFailureReason` If the merge fails (means: not stopped because of unresolved conflicts) this enum is used to explain why it failed

### Field Summary

Fields
`protected String[]` `commitNames` string versions of a list of commit SHA1s
`protected DirCache` `dircache` Directory cache
`protected boolean` `implicitDirCache` Set to true if this merger should use the default dircache of the repository and should handle locking and unlocking of the dircache.
`protected boolean` `inCore` Set to true if this merge should work in-memory.
`protected MergeAlgorithm` `mergeAlgorithm` our merge algorithm
`protected ObjectId` `resultTree` merge result as tree
`protected WorkingTreeIterator` `workingTreeIterator` The iterator to access the working tree.

### Fields inherited from class org.eclipse.jgit.merge.Merger

`db, reader, sourceCommits, sourceObjects, sourceTrees, walk`

### Constructor Summary

Constructors
`protected` `ResolveMerger(Repository local)`
`protected` `ResolveMerger(Repository local, boolean inCore)`

### Method Summary

Methods
`boolean` `failed()` Returns whether this merge failed (i.e.
`String[]` `getCommitNames()`
`Map<String,ResolveMerger.MergeFailureReason>` `getFailingPaths()`
`Map<String,MergeResult<? extends Sequence>>` `getMergeResults()`
`List<String>` `getModifiedFiles()`
`ObjectId` `getResultTreeId()`
`Map<String,DirCacheEntry>` `getToBeCheckedOut()`
`List<String>` `getUnmergedPaths()`
`protected boolean` `mergeImpl()` Execute the merge.
`protected boolean` `mergeTrees(AbstractTreeIterator baseTree, RevTree headTree, RevTree mergeTree)` The resolve conflict way of three way merging
`void` `setCommitNames(String[] commitNames)`
`void` `setDirCache(DirCache dc)` Sets the DirCache which shall be used by this merger.
`void` `setWorkingTreeIterator(WorkingTreeIterator workingTreeIterator)` Sets the WorkingTreeIterator to be used by this merger.

### Methods inherited from class org.eclipse.jgit.merge.ThreeWayMerger

`getBaseCommitId, merge, mergeBase, setBase`

### Methods inherited from class org.eclipse.jgit.merge.Merger

`getBaseCommit, getBaseCommit, getObjectInserter, getRepository, openTree, setObjectInserter`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### commitNames

    protected String[] commitNames

string versions of a list of commit SHA1s

Since:
  3.0

#### resultTree

    protected ObjectId resultTree

merge result as tree

Since:
  3.0

#### inCore

    protected boolean inCore

Set to true if this merge should work in-memory. The repos dircache and workingtree are not touched by this method. Eventually needed files are created as temporary files and a new empty, in-memory dircache will be used instead the repo's one. Often used for bare repos where the repo doesn't even have a workingtree and dircache.

Since:
  3.0

#### implicitDirCache

    protected boolean implicitDirCache

Set to true if this merger should use the default dircache of the repository and should handle locking and unlocking of the dircache. If this merger should work in-core or if an explicit dircache was specified during construction then this field is set to false.

Since:
  3.0

#### dircache

    protected DirCache dircache

Directory cache

Since:
  3.0

#### workingTreeIterator

    protected WorkingTreeIterator workingTreeIterator

The iterator to access the working tree. If set to `null` this merger will not touch the working tree.

Since:
  3.0

#### mergeAlgorithm

    protected MergeAlgorithm mergeAlgorithm

our merge algorithm

Since:
  3.0

### Constructor Detail

#### ResolveMerger

    protected ResolveMerger(Repository local,
                 boolean inCore)

Parameters:
  `local` -
  `inCore` -

#### ResolveMerger

    protected ResolveMerger(Repository local)

Parameters:
  `local` -

### Method Detail

#### mergeImpl

    protected boolean mergeImpl()
                         throws IOException

Description copied from class: `Merger`
Execute the merge.

This method is called from `Merger.merge(AnyObjectId[])` after the `Merger.sourceObjects`, `Merger.sourceCommits` and `Merger.sourceTrees` have been populated.

Specified by:
  `mergeImpl` in class `Merger`
Returns:
  true if the merge was completed without conflicts; false if the merge strategy cannot handle this merge or there were conflicts preventing it from automatically resolving all paths.
Throws:
  `IncorrectObjectTypeException` - one of the input objects is not a commit, but the strategy requires it to be a commit.
  `IOException` - one or more sources could not be read, or outputs could not be written to the Repository.

#### getResultTreeId

    public ObjectId getResultTreeId()

Specified by:
  `getResultTreeId` in class `Merger`
Returns:
  resulting tree, if `Merger.merge(AnyObjectId[])` returned true.

#### setCommitNames

    public void setCommitNames(String[] commitNames)

Parameters:
  `commitNames` - the names of the commits as they would appear in conflict markers

#### getCommitNames

    public String[] getCommitNames()

Returns:
  the names of the commits as they would appear in conflict markers.

#### getUnmergedPaths

    public List<String> getUnmergedPaths()

Returns:
  the paths with conflicts. This is a subset of the files listed by `getModifiedFiles()`

#### getModifiedFiles

    public List<String> getModifiedFiles()

Returns:
  the paths of files which have been modified by this merge. A file will be modified if a content-merge works on this path or if the merge algorithm decides to take the theirs-version. This is a superset of the files listed by `getUnmergedPaths()`.

#### getToBeCheckedOut

    public Map<String,DirCacheEntry> getToBeCheckedOut()

Returns:
  a map which maps the paths of files which have to be checked out because the merge created new fully-merged content for this file into the index. This means: the merge wrote a new stage 0 entry for this path.

#### getMergeResults

    public Map<String,MergeResult<? extends Sequence>> getMergeResults()

Returns:
  the mergeResults

#### getFailingPaths

    public Map<String,ResolveMerger.MergeFailureReason> getFailingPaths()

Returns:
  lists paths causing this merge to fail (not stopped because of a conflict). `null` is returned if this merge didn't fail.

#### failed

    public boolean failed()

Returns whether this merge failed (i.e. not stopped because of a conflict)

Returns:
  `true` if a failure occurred, `false` otherwise

#### setDirCache

    public void setDirCache(DirCache dc)

Sets the DirCache which shall be used by this merger. If the DirCache is not set explicitly and if this merger doesn't work in-core, this merger will implicitly get and lock a default DirCache. If the DirCache is explicitly set the caller is responsible to lock it in advance. Finally the merger will call `DirCache.commit()` which requires that the DirCache is locked. If the `mergeImpl()` returns without throwing an exception the lock will be released. In case of exceptions the caller is responsible to release the lock.

Parameters:
  `dc` - the DirCache to set

#### setWorkingTreeIterator

    public void setWorkingTreeIterator(WorkingTreeIterator workingTreeIterator)

Sets the WorkingTreeIterator to be used by this merger. If no WorkingTreeIterator is set this merger will ignore the working tree and fail if a content merge is necessary.

TODO: enhance WorkingTreeIterator to support write operations. Then this merger will be able to merge with a different working tree abstraction.

Parameters:
  `workingTreeIterator` - the workingTreeIt to set

#### mergeTrees

    protected boolean mergeTrees(AbstractTreeIterator baseTree,
                     RevTree headTree,
                     RevTree mergeTree)
                          throws IOException

The resolve conflict way of three way merging

Parameters:
  `baseTree` -
  `headTree` -
  `mergeTree` -
Returns:
  whether the trees merged cleanly
Throws:
  `IOException`
Since:
  3.0