// handle annotated tags
ObjectId objectId = ref.getPeeledObjectId();
if (objectId == null)
objectId = ref.getObjectId();
RevCommit srcCommit = revWalk.lookupCommit(objectId);
ObjectId headId = head.getObjectId();
if (headId == null) {
revWalk.parseHeaders(srcCommit);
dco = new DirCacheCheckout(repo,
repo.lockDirCache(), srcCommit.getTree());
dco.setFailOnConflict(true);
dco.checkout();
RefUpdate refUpdate = repo
.updateRef(head.getTarget().getName());
refUpdate.setNewObjectId(objectId);
refUpdate.setExpectedOldObjectId(null);
refUpdate.setRefLogMessage("initial pull", false);
if (refUpdate.update() != Result.NEW)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
setCallable(false);
return new MergeResult(srcCommit, srcCommit, new ObjectId[] {
null, srcCommit }, MergeStatus.FAST_FORWARD,
mergeStrategy, null, null);
}
RevCommit headCommit = revWalk.lookupCommit(headId);
if (revWalk.isMergedInto(srcCommit, headCommit)) {
setCallable(false);
return new MergeResult(headCommit, srcCommit, new ObjectId[] {
headCommit, srcCommit },
MergeStatus.ALREADY_UP_TO_DATE, mergeStrategy, null, null);
} else if (revWalk.isMergedInto(headCommit, srcCommit)) {
// FAST_FORWARD detected: skip doing a real merge but only
// update HEAD
refLogMessage.append(": " + MergeStatus.FAST_FORWARD);
dco = new DirCacheCheckout(repo,
headCommit.getTree(), repo.lockDirCache(),
srcCommit.getTree());
dco.setFailOnConflict(true);
dco.checkout();
updateHead(refLogMessage, srcCommit, headId);
setCallable(false);
return new MergeResult(srcCommit, srcCommit, new ObjectId[] {
headCommit, srcCommit }, MergeStatus.FAST_FORWARD,
mergeStrategy, null, null);
} else {
String mergeMessage = new MergeMessageFormatter().format(
commits, head);
repo.writeMergeCommitMsg(mergeMessage);
repo.writeMergeHeads(Arrays.asList(ref.getObjectId()));
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 ");
refLogMessage.append(mergeStrategy.getName());
refLogMessage.append('.');
if (noProblems) {
dco = new DirCacheCheckout(repo,
headCommit.getTree(), repo.lockDirCache(),
merger.getResultTreeId());
dco.setFailOnConflict(true);
dco.checkout();
RevCommit newHead = new Git(getRepository()).commit()
.setReflogComment(refLogMessage.toString()).call();
return new MergeResult(newHead.getId(),
null, new ObjectId[] {
headCommit.getId(), srcCommit.getId() },
MergeStatus.MERGED, mergeStrategy, null, null);
} else {
if (failingPaths != null) {