RevWalk revWalk = null;
DirCacheCheckout dco = null;
try {
Ref head = repo.getRef(Constants.HEAD);
if (head == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
StringBuilder refLogMessage = new StringBuilder("merge ");
// Check for FAST_FORWARD, ALREADY_UP_TO_DATE
revWalk = new RevWalk(repo);
// we know for now there is only one commit
Ref ref = commits.get(0);
refLogMessage.append(ref.getName());
// 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);