new ObjectId[] { headCommit, srcCommit },
MergeStatus.ABORTED, mergeStrategy, null, null);
}
String mergeMessage = "";
if (!squash) {
mergeMessage = new MergeMessageFormatter().format(
commits, head);
repo.writeMergeCommitMsg(mergeMessage);
repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
} else {
List<RevCommit> squashedCommits = RevWalkUtils.find(
revWalk, srcCommit, headCommit);
String squashMessage = new SquashMessageFormatter().format(
squashedCommits, head);
repo.writeSquashCommitMsg(squashMessage);
}
Merger merger = 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);
refLogMessage.append(": Merge made by ");
if (!revWalk.isMergedInto(headCommit, srcCommit))
refLogMessage.append(mergeStrategy.getName());
else
refLogMessage.append("recursive");
refLogMessage.append('.');
if (noProblems) {
dco = new DirCacheCheckout(repo,
headCommit.getTree(), repo.lockDirCache(),
merger.getResultTreeId());
dco.setFailOnConflict(true);
dco.checkout();
String msg = null;
RevCommit newHead = null;
MergeStatus mergeStatus = null;
if (!squash) {
newHead = new Git(getRepository()).commit()
.setReflogComment(refLogMessage.toString()).call();
mergeStatus = MergeStatus.MERGED;
} else {
msg = JGitText.get().squashCommitNotUpdatingHEAD;
newHead = headCommit;
mergeStatus = MergeStatus.MERGED_SQUASHED;
}
return new MergeResult(newHead.getId(), null,
new ObjectId[] { headCommit.getId(),
srcCommit.getId() }, mergeStatus,
mergeStrategy, null, msg);
} 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),