if (upstreamMode != null)
command.setUpstreamMode(upstreamMode);
command.call();
}
Ref headRef = repo.getRef(Constants.HEAD);
String shortHeadRef = getShortBranchName(headRef);
String refLogMessage = "checkout: moving from " + shortHeadRef;
ObjectId branch = repo.resolve(name);
if (branch == null)
throw new RefNotFoundException(MessageFormat.format(JGitText
.get().refNotResolved, name));
RevWalk revWalk = new RevWalk(repo);
AnyObjectId headId = headRef.getObjectId();
RevCommit headCommit = headId == null ? null : revWalk
.parseCommit(headId);
RevCommit newCommit = revWalk.parseCommit(branch);
RevTree headTree = headCommit == null ? null : headCommit.getTree();
DirCacheCheckout dco = new DirCacheCheckout(repo, headTree,
repo.lockDirCache(), newCommit.getTree());
dco.setFailOnConflict(true);
try {
dco.checkout();
} catch (CheckoutConflictException e) {
status = new CheckoutResult(Status.CONFLICTS, dco
.getConflicts());
throw e;
}
Ref ref = repo.getRef(name);
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
ref = null;
String toName = Repository.shortenRefName(name);
RefUpdate refUpdate = repo.updateRef(Constants.HEAD, ref == null);
refUpdate.setForceUpdate(force);
refUpdate.setRefLogMessage(refLogMessage + " to " + toName, false);
Result updateResult;
if (ref != null)
updateResult = refUpdate.link(ref.getName());
else {
refUpdate.setNewObjectId(newCommit);
updateResult = refUpdate.forceUpdate();
}