Search in sources :

Example 1 with CheckoutParams

use of org.eclipse.che.api.git.params.CheckoutParams in project che by eclipse.

the class GitProjectImporter method checkoutBranch.

private void checkoutBranch(GitConnection git, String projectName, String branchName, String startPoint) throws GitException {
    final CheckoutParams params = CheckoutParams.create(branchName);
    final boolean branchExist = git.branchList(LIST_ALL).stream().anyMatch(branch -> branch.getDisplayName().equals("origin/" + branchName));
    final GitCheckoutEvent checkout = newDto(GitCheckoutEvent.class).withWorkspaceId(WorkspaceIdProvider.getWorkspaceId()).withProjectName(projectName);
    if (startPoint != null) {
        if (branchExist) {
            git.checkout(params);
            eventService.publish(checkout.withCheckoutOnly(true).withBranchRef(getRemoteBranch(git, branchName)));
        } else {
            checkoutAndRethrow(git, params.withCreateNew(true).withStartPoint(startPoint).withNoTrack(true), FAILED_CHECKOUT_WITH_START_POINT);
            eventService.publish(checkout.withCheckoutOnly(false));
        }
    } else {
        checkoutAndRethrow(git, params, FAILED_CHECKOUT);
        eventService.publish(checkout.withCheckoutOnly(true).withBranchRef(getRemoteBranch(git, branchName)));
    }
}
Also used : CheckoutParams(org.eclipse.che.api.git.params.CheckoutParams) GitCheckoutEvent(org.eclipse.che.api.git.shared.GitCheckoutEvent)

Aggregations

CheckoutParams (org.eclipse.che.api.git.params.CheckoutParams)1 GitCheckoutEvent (org.eclipse.che.api.git.shared.GitCheckoutEvent)1