org.eclipse.jgit.merge

## Class Merger

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

Direct Known Subclasses:
  ThreeWayMerger

    public abstract class Merger
    extends Object

Instance of a specific `MergeStrategy` for a single `Repository`.

### Field Summary

Fields
`protected Repository` `db` The repository this merger operates on.
`protected ObjectReader` `reader` Reader to support `walk` and other object loading.
`protected RevCommit[]` `sourceCommits` If `sourceObjects`[i] is a commit, this is the commit.
`protected RevObject[]` `sourceObjects` The original objects supplied in the merge; this can be any tree-ish.
`protected RevTree[]` `sourceTrees` The trees matching every entry in `sourceObjects`.
`protected RevWalk` `walk` A RevWalk for computing merge bases, or listing incoming commits.

### Constructor Summary

Constructors
`protected` `Merger(Repository local)` Create a new merge instance for a repository.

### Method Summary

Methods
`RevCommit` `getBaseCommit(int aIdx, int bIdx)` Deprecated. use `getBaseCommitId()` instead, as that does not require walking the commits again
`protected RevCommit` `getBaseCommit(RevCommit a, RevCommit b)` Return the merge base of two commits.
`abstract ObjectId` `getBaseCommitId()`
`ObjectInserter` `getObjectInserter()`
`Repository` `getRepository()`
`abstract ObjectId` `getResultTreeId()`
`boolean` `merge(AnyObjectId... tips)` Merge together two or more tree-ish objects.
`protected abstract boolean` `mergeImpl()` Execute the merge.
`protected AbstractTreeIterator` `openTree(AnyObjectId treeId)` Open an iterator over a tree.
`void` `setObjectInserter(ObjectInserter oi)` Set the inserter this merger will use to create objects.

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

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

### Field Detail

#### db

    protected final Repository db

The repository this merger operates on.

#### reader

    protected final ObjectReader reader

Reader to support `walk` and other object loading.

#### walk

    protected final RevWalk walk

A RevWalk for computing merge bases, or listing incoming commits.

#### sourceObjects

    protected RevObject[] sourceObjects

The original objects supplied in the merge; this can be any tree-ish.

#### sourceCommits

    protected RevCommit[] sourceCommits

If `sourceObjects`[i] is a commit, this is the commit.

#### sourceTrees

    protected RevTree[] sourceTrees

The trees matching every entry in `sourceObjects`.

### Constructor Detail

#### Merger

    protected Merger(Repository local)

Create a new merge instance for a repository.

Parameters:
  `local` - the repository this merger will read and write data on.

### Method Detail

#### getRepository

    public Repository getRepository()

Returns:
  the repository this merger operates on.

#### getObjectInserter

    public ObjectInserter getObjectInserter()

Returns:
  an object writer to create objects in `getRepository()`. If no inserter has been set on this instance, one will be created and returned by all future calls.

#### setObjectInserter

    public void setObjectInserter(ObjectInserter oi)

Set the inserter this merger will use to create objects.

If an inserter was already set on this instance (such as by a prior set, or a prior call to `getObjectInserter()`), the prior inserter will be released first.

Parameters:
  `oi` - the inserter instance to use. Must be associated with the repository instance returned by `getRepository()`.

#### merge

    public boolean merge(AnyObjectId... tips)
                  throws IOException

Merge together two or more tree-ish objects.

Any tree-ish may be supplied as inputs. Commits and/or tags pointing at trees or commits may be passed as input objects.

Parameters:
  `tips` - source trees to be combined together. The merge base is not included in this set.
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.

#### getBaseCommitId

    public abstract ObjectId getBaseCommitId()

Returns:
  the ID of the commit that was used as merge base for merging, or null if no merge base was used or it was set manually
Since:
  3.2

#### getBaseCommit

    @Deprecated
    public RevCommit getBaseCommit(int aIdx,
                                     int bIdx)
                            throws IncorrectObjectTypeException,
                                   IOException

Deprecated. use `getBaseCommitId()` instead, as that does not require walking the commits again
Return the merge base of two commits.

Parameters:
  `aIdx` - index of the first commit in `sourceObjects`.
  `bIdx` - index of the second commit in `sourceObjects`.
Returns:
  the merge base of two commits
Throws:
  `IncorrectObjectTypeException` - one of the input objects is not a commit.
  `IOException` - objects are missing or multiple merge bases were found.

#### getBaseCommit

    protected RevCommit getBaseCommit(RevCommit a,
                          RevCommit b)
                               throws IncorrectObjectTypeException,
                                      IOException

Return the merge base of two commits.

Parameters:
  `a` - the first commit in `sourceObjects`.
  `b` - the second commit in `sourceObjects`.
Returns:
  the merge base of two commits
Throws:
  `IncorrectObjectTypeException` - one of the input objects is not a commit.
  `IOException` - objects are missing or multiple merge bases were found.
Since:
  3.0

#### openTree

    protected AbstractTreeIterator openTree(AnyObjectId treeId)
                                     throws IncorrectObjectTypeException,
                                            IOException

Open an iterator over a tree.

Parameters:
  `treeId` - the tree to scan; must be a tree (not a treeish).
Returns:
  an iterator for the tree.
Throws:
  `IncorrectObjectTypeException` - the input object is not a tree.
  `IOException` - the tree object is not found or cannot be read.

#### mergeImpl

    protected abstract boolean mergeImpl()
                                  throws IOException

Execute the merge.

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

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 abstract ObjectId getResultTreeId()

Returns:
  resulting tree, if `merge(AnyObjectId[])` returned true.