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() }); //$NON-NLS-1$ //$NON-NLS-2$
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 "); //$NON-NLS-1$
if (!revWalk.isMergedInto(headCommit, srcCommit))
refLogMessage.append(mergeStrategy.getName());
else
refLogMessage.append("recursive"); //$NON-NLS-1$
refLogMessage.append('.');
if (noProblems) {
dco = new DirCacheCheckout(repo,
headCommit.getTree(), repo.lockDirCache(),
merger.getResultTreeId());
dco.setFailOnConflict(true);
dco.checkout();
String msg = null;
ObjectId newHeadId = null;
MergeStatus mergeStatus = null;
if (!commit && squash) {
mergeStatus = MergeStatus.MERGED_SQUASHED_NOT_COMMITTED;
}
if (!commit && !squash) {
mergeStatus = MergeStatus.MERGED_NOT_COMMITTED;
}
if (commit && !squash) {
newHeadId = new Git(getRepository()).commit()
.setReflogComment(refLogMessage.toString())
.call().getId();
mergeStatus = MergeStatus.MERGED;
}
if (commit && squash) {
msg = JGitText.get().squashCommitNotUpdatingHEAD;
newHeadId = headCommit.getId();
mergeStatus = MergeStatus.MERGED_SQUASHED;
}
return new MergeResult(newHeadId, 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.getBaseCommitId(),
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.getBaseCommitId(),
new ObjectId[] { headCommit.getId(),
srcCommit.getId() },
MergeStatus.CONFLICTING, mergeStrategy,
lowLevelResults, null);
}