}
Git git = new Git(FileRepositoryBuilder.create(gitDir));
if (paths != null) {
Set<String> toRemove = new HashSet<String>();
CheckoutCommand checkout = git.checkout();
for (int i = 0; i < paths.length(); i++) {
String p = paths.getString(i);
if (removeUntracked && !isInIndex(git.getRepository(), p))
toRemove.add(p);
checkout.addPath(p);
}
checkout.call();
for (String p : toRemove) {
File f = new File(git.getRepository().getWorkTree(), p);
f.delete();
}
return true;
} else if (tag != null && branch != null) {
CheckoutCommand co = git.checkout();
try {
co.setName(branch).setStartPoint(tag).setCreateBranch(true).call();
return true;
} catch (RefNotFoundException e) {
String msg = NLS.bind("Tag not found: {0}", EncodingUtils.encodeForHTML(tag));
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, e));
} catch (GitAPIException e) {
if (org.eclipse.jgit.api.CheckoutResult.Status.CONFLICTS.equals(co.getResult().getStatus())) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_CONFLICT,
"Checkout aborted.", e));
}
// TODO: handle other exceptions
}
} else if (branch != null) {
if (!isLocalBranch(git, branch)) {
String msg = NLS.bind("{0} is not a branch.", EncodingUtils.encodeForHTML(branch));
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
}
CheckoutCommand co = git.checkout();
try {
co.setName(Constants.R_HEADS + branch).call();
return true;
} catch (CheckoutConflictException e) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_CONFLICT,
"Checkout aborted.", e));
} catch (RefNotFoundException e) {