Search in sources :

Example 1 with FeatureCheckoutOperation

use of org.eclipse.egit.gitflow.op.FeatureCheckoutOperation in project egit by eclipse.

the class FeatureCheckoutHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    Repository repository = gfRepo.getRepository();
    final List<Ref> refs = gfRepo.getFeatureBranches();
    FeatureBranchSelectionDialog dialog = new FeatureBranchSelectionDialog(HandlerUtil.getActiveShell(event), refs, UIText.FeatureCheckoutHandler_selectFeature, UIText.FeatureCheckoutHandler_localFeatures, Constants.R_HEADS + gfRepo.getConfig().getFeaturePrefix(), gfRepo);
    if (dialog.open() != Window.OK) {
        return null;
    }
    final Ref ref = dialog.getSelectedNode();
    try {
        String featureName = gfRepo.getFeatureBranchName(ref);
        // TODO: consider using BranchOperationUI because checkout can take
        // a long time on large repositories
        FeatureCheckoutOperation checkoutOperation = new FeatureCheckoutOperation(gfRepo, featureName);
        JobUtil.scheduleUserWorkspaceJob(checkoutOperation, UIText.FeatureCheckoutHandler_checkingOutFeature, JobFamilies.GITFLOW_FAMILY);
        IJobManager jobMan = Job.getJobManager();
        try {
            jobMan.join(GITFLOW_FAMILY, null);
        } catch (OperationCanceledException | InterruptedException e) {
            return error(e.getMessage(), e);
        }
        CheckoutResult result = checkoutOperation.getResult();
        if (!CheckoutResult.Status.OK.equals(result.getStatus())) {
            Shell shell = HandlerUtil.getActiveShell(event);
            if (!handleUncommittedFiles(gfRepo.getRepository(), shell, repository.getWorkTree().getName())) {
                return Status.CANCEL_STATUS;
            } else {
                JobUtil.scheduleUserWorkspaceJob(checkoutOperation, UIText.FeatureCheckoutHandler_checkingOutFeature, JobFamilies.GITFLOW_FAMILY);
            }
        }
    } catch (GitAPIException e) {
        throw new RuntimeException(e);
    }
    return null;
}
Also used : FeatureCheckoutOperation(org.eclipse.egit.gitflow.op.FeatureCheckoutOperation) FeatureBranchSelectionDialog(org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) Shell(org.eclipse.swt.widgets.Shell) CheckoutResult(org.eclipse.jgit.api.CheckoutResult) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 IJobManager (org.eclipse.core.runtime.jobs.IJobManager)1 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)1 FeatureCheckoutOperation (org.eclipse.egit.gitflow.op.FeatureCheckoutOperation)1 FeatureBranchSelectionDialog (org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog)1 CheckoutResult (org.eclipse.jgit.api.CheckoutResult)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1 Shell (org.eclipse.swt.widgets.Shell)1