Search in sources :

Example 1 with ResetType

use of org.eclipse.jgit.api.ResetCommand.ResetType in project egit by eclipse.

the class ResetCommand method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final RepositoryTreeNode<?> node = getSelectedNodes(event).get(0);
    final String currentBranch;
    try {
        currentBranch = node.getRepository().getFullBranch();
    } catch (IOException e1) {
        throw new ExecutionException(e1.getMessage(), e1);
    }
    if (!(node.getObject() instanceof Ref)) {
        // allowing reset to any commit
        return new ResetActionHandler().execute(event);
    }
    // If a ref is selected in the repository view, only reset to
    // that ref will be possible.
    final Ref targetBranch = (Ref) node.getObject();
    final String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(node.getRepository());
    Wizard wiz = new Wizard() {

        @Override
        public void addPages() {
            addPage(new SelectResetTypePage(repoName, node.getRepository(), currentBranch, targetBranch.getName()));
            setWindowTitle(UIText.ResetCommand_WizardTitle);
        }

        @Override
        public boolean performFinish() {
            final ResetType resetType = ((SelectResetTypePage) getPages()[0]).getResetType();
            ResetMenu.performReset(getShell(), node.getRepository(), targetBranch.getObjectId(), resetType);
            return true;
        }
    };
    WizardDialog dlg = new WizardDialog(getShell(event), wiz);
    dlg.setHelpAvailable(false);
    dlg.open();
    return null;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) SelectResetTypePage(org.eclipse.egit.ui.internal.repository.SelectResetTypePage) ResetActionHandler(org.eclipse.egit.ui.internal.actions.ResetActionHandler) ResetType(org.eclipse.jgit.api.ResetCommand.ResetType) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Wizard(org.eclipse.jface.wizard.Wizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 2 with ResetType

use of org.eclipse.jgit.api.ResetCommand.ResetType in project egit by eclipse.

the class ResetActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(true, event);
    if (repository == null)
        return null;
    if (!repository.getRepositoryState().canResetHead()) {
        MessageDialog.openError(getShell(event), UIText.ResetAction_errorResettingHead, NLS.bind(UIText.ResetAction_repositoryState, repository.getRepositoryState().getDescription()));
        return null;
    }
    ResetTargetSelectionDialog branchSelectionDialog = new ResetTargetSelectionDialog(getShell(event), repository);
    if (branchSelectionDialog.open() == IDialogConstants.OK_ID) {
        final String refName = branchSelectionDialog.getRefName();
        final ResetType type = branchSelectionDialog.getResetType();
        String jobname = NLS.bind(UIText.ResetAction_reset, refName);
        final ResetOperation operation = new ResetOperation(repository, refName, type);
        JobUtil.scheduleUserWorkspaceJob(operation, jobname, JobFamilies.RESET);
    }
    return null;
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) Repository(org.eclipse.jgit.lib.Repository) ResetTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.ResetTargetSelectionDialog) ResetType(org.eclipse.jgit.api.ResetCommand.ResetType)

Aggregations

ResetType (org.eclipse.jgit.api.ResetCommand.ResetType)2 IOException (java.io.IOException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ResetOperation (org.eclipse.egit.core.op.ResetOperation)1 ResetActionHandler (org.eclipse.egit.ui.internal.actions.ResetActionHandler)1 ResetTargetSelectionDialog (org.eclipse.egit.ui.internal.dialogs.ResetTargetSelectionDialog)1 SelectResetTypePage (org.eclipse.egit.ui.internal.repository.SelectResetTypePage)1 Wizard (org.eclipse.jface.wizard.Wizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Ref (org.eclipse.jgit.lib.Ref)1 Repository (org.eclipse.jgit.lib.Repository)1