Search in sources :

Example 1 with FeatureBranchSelectionDialog

use of org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog 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)

Example 2 with FeatureBranchSelectionDialog

use of org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog in project egit by eclipse.

the class FeatureTrackHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    final List<Ref> refs = new ArrayList<Ref>();
    Shell activeShell = HandlerUtil.getActiveShell(event);
    int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
    FeatureListOperation featureListOperation = new FeatureListOperation(gfRepo, timeout);
    JobUtil.scheduleUserWorkspaceJob(featureListOperation, UIText.FeatureTrackHandler_fetchingRemoteFeatures, GITFLOW_FAMILY);
    IJobManager jobMan = Job.getJobManager();
    try {
        jobMan.join(GITFLOW_FAMILY, null);
    } catch (OperationCanceledException | InterruptedException e) {
        return error(e.getMessage(), e);
    }
    List<Ref> remoteFeatures = featureListOperation.getResult();
    if (remoteFeatures.isEmpty()) {
        MessageDialog.openInformation(activeShell, UIText.FeatureTrackHandler_noRemoteFeatures, UIText.FeatureTrackHandler_noRemoteFeaturesFoundOnTheConfiguredRemote);
    }
    refs.addAll(remoteFeatures);
    FeatureBranchSelectionDialog dialog = new FeatureBranchSelectionDialog(HandlerUtil.getActiveShell(event), refs, UIText.FeatureCheckoutHandler_selectFeature, UIText.FeatureTrackHandler_remoteFeatures, R_REMOTES + DEFAULT_REMOTE_NAME + SEP + gfRepo.getConfig().getFeaturePrefix(), gfRepo);
    if (dialog.open() != Window.OK) {
        return Status.CANCEL_STATUS;
    }
    Ref ref = dialog.getSelectedNode();
    FeatureTrackOperation featureTrackOperation = new FeatureTrackOperation(gfRepo, ref, timeout);
    JobUtil.scheduleUserWorkspaceJob(featureTrackOperation, UIText.FeatureTrackHandler_trackingFeature, GITFLOW_FAMILY);
    return null;
}
Also used : FeatureBranchSelectionDialog(org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) FeatureTrackOperation(org.eclipse.egit.gitflow.op.FeatureTrackOperation) Ref(org.eclipse.jgit.lib.Ref) Shell(org.eclipse.swt.widgets.Shell) FeatureListOperation(org.eclipse.egit.gitflow.op.FeatureListOperation) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Aggregations

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