String mergeMessage = new MergeMessageFormatter().format(
commits, head);
repo.writeMergeCommitMsg(mergeMessage);
repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
ThreeWayMerger merger = (ThreeWayMerger) mergeStrategy
.newMerger(repo);
boolean noProblems;
Map<String, org.eclipse.jgit.merge.MergeResult<?>> lowLevelResults = null;
Map<String, MergeFailureReason> failingPaths = null;
List<String> unmergedPaths = null;
if (merger instanceof ResolveMerger) {
ResolveMerger resolveMerger = (ResolveMerger) merger;
resolveMerger.setCommitNames(new String[] {
"BASE", "HEAD", ref.getName() });
resolveMerger.setWorkingTreeIterator(new FileTreeIterator(repo));
noProblems = merger.merge(headCommit, srcCommit);
lowLevelResults = resolveMerger
.getMergeResults();
failingPaths = resolveMerger.getFailingPaths();
unmergedPaths = resolveMerger.getUnmergedPaths();
} else
noProblems = merger.merge(headCommit, srcCommit);
if (noProblems) {
DirCacheCheckout dco = new DirCacheCheckout(repo,
headCommit.getTree(), repo.lockDirCache(),
merger.getResultTreeId());
dco.setFailOnConflict(true);
dco.checkout();
RevCommit newHead = new Git(getRepository()).commit().call();
return new MergeResult(newHead.getId(),
null, new ObjectId[] {
headCommit.getId(), srcCommit.getId() },
MergeStatus.MERGED, mergeStrategy, null, null);
} else {
if (failingPaths != null) {
repo.writeMergeCommitMsg(null);
repo.writeMergeHeads(null);
return new MergeResult(null,
merger.getBaseCommit(0, 1),
new ObjectId[] {
headCommit.getId(), srcCommit.getId() },
MergeStatus.FAILED, mergeStrategy,
lowLevelResults, failingPaths, null);
} else {
String mergeMessageWithConflicts = new MergeMessageFormatter()
.formatWithConflicts(mergeMessage,
unmergedPaths);
repo.writeMergeCommitMsg(mergeMessageWithConflicts);
return new MergeResult(null,
merger.getBaseCommit(0, 1),
new ObjectId[] { headCommit.getId(),
srcCommit.getId() },
MergeStatus.CONFLICTING, mergeStrategy,
lowLevelResults, null);
}