Search in sources :

Example 31 with GitFlowRepository

use of org.eclipse.egit.gitflow.GitFlowRepository in project egit by eclipse.

the class DevelopCompareHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final GitFlowRepository gfRepo = GitFlowHandlerUtil.getRepository(event);
    if (gfRepo == null) {
        return error(UIText.Handlers_noGitflowRepositoryFound);
    }
    IResource[] selectedResources = GitFlowHandlerUtil.gatherResourceToOperateOn(event);
    String revision;
    try {
        revision = GitFlowHandlerUtil.gatherRevision(event);
    } catch (OperationCanceledException e) {
        return null;
    } catch (IOException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
    IWorkbenchPage workBenchPage = getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        CompareUtils.compare(selectedResources, gfRepo.getRepository(), HEAD, revision, true, workBenchPage);
    } catch (IOException e) {
        handleError(CompareWithRefAction_errorOnSynchronize, e, true);
    }
    return null;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) IResource(org.eclipse.core.resources.IResource)

Example 32 with GitFlowRepository

use of org.eclipse.egit.gitflow.GitFlowRepository 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 33 with GitFlowRepository

use of org.eclipse.egit.gitflow.GitFlowRepository in project egit by eclipse.

the class FeatureFinishHandler method rewordCommitMessage.

private void rewordCommitMessage(Shell activeShell, final GitFlowRepository gfRepo) throws CoreException, IOException {
    Repository repository = gfRepo.getRepository();
    CommitHelper commitHelper = new CommitHelper(repository);
    CommitMessageEditorDialog messageEditorDialog = new CommitMessageEditorDialog(activeShell, repository.readSquashCommitMsg(), UIText.FeatureFinishHandler_rewordSquashedCommitMessage);
    if (Window.OK == messageEditorDialog.open()) {
        String commitMessage = stripCommentLines(messageEditorDialog.getCommitMessage());
        CommitOperation commitOperation = new CommitOperation(repository, commitHelper.getAuthor(), commitHelper.getCommitter(), commitMessage);
        commitOperation.execute(null);
    }
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) CommitMessageEditorDialog(org.eclipse.egit.ui.internal.rebase.CommitMessageEditorDialog) CommitOperation(org.eclipse.egit.core.op.CommitOperation) CommitHelper(org.eclipse.egit.ui.internal.commit.CommitHelper)

Example 34 with GitFlowRepository

use of org.eclipse.egit.gitflow.GitFlowRepository 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)

Example 35 with GitFlowRepository

use of org.eclipse.egit.gitflow.GitFlowRepository in project egit by eclipse.

the class GitFlowHandlerUtil method getRepository.

/**
 * @param event
 * @return Selected GitFlowRepository
 */
@Nullable
public static GitFlowRepository getRepository(ExecutionEvent event) {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    IStructuredSelection structuredSelection = SelectionUtils.getStructuredSelection(selection);
    Repository repository = SelectionUtils.getRepository(structuredSelection);
    if (repository == null) {
        return null;
    }
    return new GitFlowRepository(repository);
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Nullable(org.eclipse.jgit.annotations.Nullable)

Aggregations

GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)57 Repository (org.eclipse.jgit.lib.Repository)35 Test (org.junit.Test)33 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)7 BranchOperation (org.eclipse.egit.core.op.BranchOperation)7 IOException (java.io.IOException)6 CoreException (org.eclipse.core.runtime.CoreException)6 Shell (org.eclipse.swt.widgets.Shell)6 IJobManager (org.eclipse.core.runtime.jobs.IJobManager)5 WrongGitFlowStateException (org.eclipse.egit.gitflow.WrongGitFlowStateException)5 File (java.io.File)4 Ref (org.eclipse.jgit.lib.Ref)4 GitFlowConfig (org.eclipse.egit.gitflow.GitFlowConfig)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 ExecutionException (org.eclipse.core.commands.ExecutionException)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 InitParameters (org.eclipse.egit.gitflow.InitParameters)2 FeatureBranchSelectionDialog (org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2