Search in sources :

Example 1 with NotSupportedException

use of org.eclipse.jgit.errors.NotSupportedException in project egit by eclipse.

the class PushOperationUI method createPushOperation.

private void createPushOperation() throws CoreException {
    if (remoteName != null) {
        op = new PushOperation(repository, remoteName, dryRun, getTimeout());
        return;
    }
    if (spec == null) {
        // spec == null => config was supplied in constructor
        // we don't use the configuration directly, as it may contain
        // unsaved changes and as we may need
        // to add the default push RefSpec here
        spec = new PushOperationSpecification();
        List<URIish> urisToPush = new ArrayList<>();
        for (URIish uri : config.getPushURIs()) urisToPush.add(uri);
        if (urisToPush.isEmpty() && !config.getURIs().isEmpty())
            urisToPush.add(config.getURIs().get(0));
        List<RefSpec> pushRefSpecs = new ArrayList<>();
        pushRefSpecs.addAll(config.getPushRefSpecs());
        for (URIish uri : urisToPush) {
            try {
                // Fetch ref specs are passed here to make sure that the
                // returned remote ref updates include tracking branch
                // updates.
                Collection<RemoteRefUpdate> remoteRefUpdates = Transport.findRemoteRefUpdatesFor(repository, pushRefSpecs, config.getFetchRefSpecs());
                spec.addURIRefUpdates(uri, remoteRefUpdates);
            } catch (NotSupportedException e) {
                throw new CoreException(Activator.createErrorStatus(e.getMessage(), e));
            } catch (IOException e) {
                throw new CoreException(Activator.createErrorStatus(e.getMessage(), e));
            }
        }
    }
    op = new PushOperation(repository, spec, dryRun, getTimeout());
}
Also used : URIish(org.eclipse.jgit.transport.URIish) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) RefSpec(org.eclipse.jgit.transport.RefSpec) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) IOException(java.io.IOException) PushOperation(org.eclipse.egit.core.op.PushOperation) NotSupportedException(org.eclipse.jgit.errors.NotSupportedException)

Example 2 with NotSupportedException

use of org.eclipse.jgit.errors.NotSupportedException in project jbosstools-openshift by jbosstools.

the class EGitUtils method createPushSpec.

/**
 * Creates a push operation specification for the given push uris to the
 * given push operation specification.
 *
 * @param pushURIs
 *            the push uri's
 * @param pushRefSpecs
 *            the push ref specs
 * @param fetchRefSpecs
 * @param repository
 *            the repository
 * @return the push operation specification
 * @throws CoreException
 *             the core exception
 */
private static PushOperationSpecification createPushSpec(Collection<URIish> pushURIs, Collection<RefSpec> pushRefSpecs, Collection<RefSpec> fetchRefSpecs, Repository repository) throws CoreException {
    try {
        PushOperationSpecification pushSpec = new PushOperationSpecification();
        final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(repository, pushRefSpecs, fetchRefSpecs);
        if (updates.isEmpty()) {
            throw new CoreException(new Status(IStatus.ERROR, EGitCoreActivator.PLUGIN_ID, "There's no local source ref that match the remote refs (local refs changed?)"));
        }
        for (URIish uri : pushURIs) {
            pushSpec.addURIRefUpdates(uri, copy(updates));
        }
        return pushSpec;
    } catch (NotSupportedException e) {
        throw new CoreException(createStatus(e, "Could not connect repository \"{0}\" to a remote", repository.toString()));
    } catch (IOException e) {
        throw new CoreException(createStatus(e, "Could not convert remote specifications for repository \"{0}\" to a remote", repository.toString()));
    }
}
Also used : RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) BranchTrackingStatus(org.eclipse.jgit.lib.BranchTrackingStatus) URIish(org.eclipse.jgit.transport.URIish) CoreException(org.eclipse.core.runtime.CoreException) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) IOException(java.io.IOException) NotSupportedException(org.eclipse.jgit.errors.NotSupportedException)

Aggregations

IOException (java.io.IOException)2 CoreException (org.eclipse.core.runtime.CoreException)2 PushOperationSpecification (org.eclipse.egit.core.op.PushOperationSpecification)2 NotSupportedException (org.eclipse.jgit.errors.NotSupportedException)2 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)2 URIish (org.eclipse.jgit.transport.URIish)2 ArrayList (java.util.ArrayList)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 PushOperation (org.eclipse.egit.core.op.PushOperation)1 BranchTrackingStatus (org.eclipse.jgit.lib.BranchTrackingStatus)1 RefSpec (org.eclipse.jgit.transport.RefSpec)1