Search in sources :

Example 11 with PushOperationSpecification

use of org.eclipse.egit.core.op.PushOperationSpecification in project egit by eclipse.

the class ConfirmationPage method revalidateImpl.

private void revalidateImpl() {
    if (getControl().isDisposed() || !isCurrentPage())
        return;
    final List<RefSpec> fetchSpecs;
    if (displayedRepoSelection.isConfigSelected())
        fetchSpecs = displayedRepoSelection.getConfig().getFetchRefSpecs();
    else
        fetchSpecs = null;
    final PushOperation operation;
    try {
        final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(local, displayedRefSpecs, fetchSpecs);
        if (updates.isEmpty()) {
            // It can happen only when local refs changed in the mean time.
            setErrorMessage(UIText.ConfirmationPage_errorRefsChangedNoMatch);
            setPageComplete(false);
            return;
        }
        final PushOperationSpecification spec = new PushOperationSpecification();
        for (final URIish uri : displayedRepoSelection.getPushURIs()) spec.addURIRefUpdates(uri, copyUpdates(updates));
        int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
        operation = new PushOperation(local, spec, true, timeout);
        if (credentials != null)
            operation.setCredentialsProvider(new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword()));
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                operation.run(monitor);
            }
        });
    } catch (final IOException e) {
        setErrorMessage(NLS.bind(UIText.ConfirmationPage_errorCantResolveSpecs, e.getMessage()));
        return;
    } catch (final InvocationTargetException e) {
        setErrorMessage(NLS.bind(UIText.ConfirmationPage_errorUnexpected, e.getCause().getMessage()));
        return;
    } catch (final InterruptedException e) {
        setErrorMessage(UIText.ConfirmationPage_errorInterrupted);
        setPageComplete(true);
        displayedRefSpecs = null;
        displayedRepoSelection = null;
        return;
    }
    final PushOperationResult result = operation.getOperationResult();
    resultPanel.setData(local, result);
    if (result.isSuccessfulConnectionForAnyURI()) {
        setPageComplete(true);
        confirmedResult = result;
    } else {
        final String message = NLS.bind(UIText.ConfirmationPage_cantConnectToAny, result.getErrorStringForAllURis());
        setErrorMessage(message);
        ErrorDialog.openError(getShell(), UIText.ConfirmationPage_cantConnectToAnyTitle, null, new Status(IStatus.ERROR, Activator.getPluginId(), message));
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) URIish(org.eclipse.jgit.transport.URIish) PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) PushOperation(org.eclipse.egit.core.op.PushOperation) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RefSpec(org.eclipse.jgit.transport.RefSpec) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification)

Example 12 with PushOperationSpecification

use of org.eclipse.egit.core.op.PushOperationSpecification in project egit by eclipse.

the class PushToGerritPage method doPush.

void doPush() {
    try {
        URIish uri = new URIish(uriCombo.getText());
        Ref currentHead = repository.exactRef(Constants.HEAD);
        String ref = prefixCombo.getItem(prefixCombo.getSelectionIndex()) + branchText.getText().trim();
        if (topicText.isEnabled()) {
            ref = setTopicInRef(ref, topicText.getText().trim());
        }
        RemoteRefUpdate update = new RemoteRefUpdate(repository, currentHead, ref, false, null, null);
        PushOperationSpecification spec = new PushOperationSpecification();
        spec.addURIRefUpdates(uri, Arrays.asList(update));
        final PushOperationUI op = new PushOperationUI(repository, spec, false);
        storeLastUsedUri(uriCombo.getText());
        storeLastUsedBranch(branchText.getText());
        storeLastUsedTopic(topicText.isEnabled(), topicText.getText().trim(), repository.getBranch());
        op.setPushMode(PushMode.GERRIT);
        op.start();
    } catch (URISyntaxException | IOException e) {
        Activator.handleError(e.getMessage(), e, true);
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) Ref(org.eclipse.jgit.lib.Ref) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Aggregations

PushOperationSpecification (org.eclipse.egit.core.op.PushOperationSpecification)12 URIish (org.eclipse.jgit.transport.URIish)10 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)9 PushOperation (org.eclipse.egit.core.op.PushOperation)8 IOException (java.io.IOException)5 PushOperationResult (org.eclipse.egit.core.op.PushOperationResult)5 ArrayList (java.util.ArrayList)4 RefSpec (org.eclipse.jgit.transport.RefSpec)4 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)3 CoreException (org.eclipse.core.runtime.CoreException)2 NotSupportedException (org.eclipse.jgit.errors.NotSupportedException)2 Test (org.junit.Test)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 Collection (java.util.Collection)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1