public class CheckoutCommitHandler extends AbstractHistoryCommandHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
ObjectId commitId = getSelectedCommitId(event);
Repository repo = getRepository(event);
final BranchOperationUI op;
List<RefNode> nodes = getRefNodes(commitId, repo, Constants.R_HEADS,
Constants.R_REMOTES);
Collections.sort(nodes);
if (nodes.isEmpty())
op = BranchOperationUI.checkout(repo, commitId.name());
else if (nodes.size() == 1)
op = BranchOperationUI.checkout(repo, nodes.get(0).getObject().getName());
else {
BranchSelectionDialog<RefNode> dlg = new BranchSelectionDialog<RefNode>(
HandlerUtil.getActiveShellChecked(event), nodes,
UIText.CheckoutHandler_SelectBranchTitle,
UIText.CheckoutHandler_SelectBranchMessage, SWT.SINGLE);
if (dlg.open() == Window.OK) {
op = BranchOperationUI.checkout(repo, dlg.getSelectedNode()
.getObject().getName());
} else {
op = null;
}
}
if (op == null)
return null;
op.start();
return null;
}