Example usage for org.eclipse.jgit.transport Transport fetch

List of usage examples for org.eclipse.jgit.transport Transport fetch

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport Transport fetch.

Prototype

List fetch

To view the source code for org.eclipse.jgit.transport Transport fetch.

Click Source Link

Document

Specifications to apply during fetch.

Usage

From source file:com.gmail.cjbooms.thesis.pythonappengine.server.git.GitCommandsServiceImpl.java

License:Open Source License

/**
 * Pull changes from Remote Repository//  w ww  . j a  v a  2s .com
 *
 * @param pathToLocalRepository Root Location Of Repository or Project
 * @param remoteRepoURL The URL of the Remote Repository to push to
 * @param userName The remote login user name
 * @param password The remote login password
 * @throws IOException, GitAPIException, URISyntaxException
 */
public void pullChangesFromRemoteRepository(String pathToLocalRepository, String remoteRepoURL, String userName,
        String password) throws IOException {

    File repositoryDirectory = new File(pathToLocalRepository);
    Git localGitRepositoryRef = Git.open(repositoryDirectory);
    Repository localRepository = localGitRepositoryRef.getRepository();

    URIish remoteURI = null;
    try {
        remoteURI = new URIish(remoteRepoURL);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage());
    }
    Transport t = Transport.open(localRepository, remoteURI);
    ((TransportHttp) t).setUseSmartHttp(true);
    t.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, password));
    RefSpec refSpec = new RefSpec("+refs/heads/*:refs/heads/*");

    t.fetch(NullProgressMonitor.INSTANCE, Collections.singleton(refSpec));

}

From source file:com.madgag.agit.GitFetchService.java

License:Open Source License

public FetchResult fetch(RemoteConfig remote, Collection<RefSpec> toFetch) {
    Log.d(TAG, "About to run fetch : " + remote.getName() + " " + remote.getURIs());

    Transport transport = transportFactory.transportFor(remote);
    try {/*from w ww  . ja v a2s. c  om*/
        FetchResult fetchResult = transport
                .fetch(new MessagingProgressMonitor(progressListener, cancellationSignaller), toFetch);
        Log.d(TAG, "Fetch complete with : " + fetchResult);
        for (TrackingRefUpdate update : fetchResult.getTrackingRefUpdates()) {
            Log.d(TAG, "TrackingRefUpdate : " + update.getLocalName() + " old=" + update.getOldObjectId()
                    + " new=" + update.getNewObjectId());
        }
        repoUpdateBroadcaster.broadcastUpdate();
        return fetchResult;
    } catch (NotSupportedException e) {
        throw new RuntimeException(e);
    } catch (TransportException e) {
        Log.e(TAG, "TransportException ", e);
        String message = e.getMessage();
        Throwable cause = e.getCause();
        if (cause != null && cause instanceof JSchException) {
            message = "SSH: " + ((JSchException) cause).getMessage();
        }
        throw new RuntimeException(message, e);
    } finally {
        Log.d(TAG, "Closing transport " + transport);
        transport.close();
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.java

License:Apache License

@NotNull
public static FetchResult fetch(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings,
        @NotNull TransportFactory transportFactory, @NotNull Transport transport,
        @NotNull ProgressMonitor progress, @NotNull Collection<RefSpec> refSpecs)
        throws NotSupportedException, TransportException, VcsException {
    try {/*  w  w  w .j  a v  a 2  s . co  m*/
        return transport.fetch(progress, refSpecs);
    } catch (TransportException e) {
        Throwable cause = e.getCause();
        if (cause instanceof JSchException && "channel is not opened.".equals(cause.getMessage())) {
            Transport tn = null;
            try {
                tn = transportFactory.createTransport(r, url, authSettings);
                return tn.fetch(progress, refSpecs);
            } finally {
                if (tn != null)
                    tn.close();
            }
        } else {
            throw e;
        }
    }
}

From source file:net.erdfelt.android.sdkfido.git.internal.GitCloneCommand.java

License:Apache License

/**
 * Fetch only specific refs from the remoteName.
 * //from w  w w .  j  a  v  a 2s .co m
 * @param remoteName
 *            the remote name to fetch from
 * @param refs
 *            the specific refs to fetch, or null for all refs
 * @return the results of the fetch
 * @throws URISyntaxException
 *             if unable to process the URL for the remote name
 * @throws IOException
 *             if unable to fetch
 */
private FetchResult fetch(String remoteName, Collection<RefSpec> refs) throws URISyntaxException, IOException {
    if (refs == null) {
        LOG.info("fetch: remote:" + remoteName + " - refs:<all>");
    } else {
        LOG.info("fetch: remote:" + remoteName + " - refs:" + refs);
    }
    Transport tx = Transport.open(repo, remoteName);
    FetchResult result = null;

    try {
        result = tx.fetch(getProgressMonitor(), refs);
    } finally {
        tx.close();
    }

    GitInfo.infoFetchResults(repo, result);
    return result;
}

From source file:org.commonjava.gitwrap.BareGitRepository.java

License:Open Source License

public BareGitRepository fetch(final String remoteName) throws GitWrapException {
    Transport transport = null;
    try {//from ww  w . j ava2 s. c o m
        final RemoteConfig remoteConfig = new RemoteConfig(repository.getConfig(), remoteName);
        if (remoteConfig.getURIs() == null || remoteConfig.getURIs().isEmpty()) {
            throw new GitWrapException("Remote: %s has no associated URLs.", remoteName);
        }

        if (remoteConfig.getFetchRefSpecs() == null || remoteConfig.getFetchRefSpecs().isEmpty()) {
            throw new GitWrapException("Remote: %s has no associated fetch ref-specs.", remoteName);
        }

        transport = Transport.open(repository, remoteConfig);
        latestFetch = transport.fetch(MONITOR, null);
    } catch (final URISyntaxException e) {
        throw new GitWrapException("Cannot read configuration for remote: %s. Reason: %s", e, remoteName,
                e.getMessage());
    } catch (final NotSupportedException e) {
        throw new GitWrapException("Transport not supported for remote: %s. Error was: %s", e, remoteName,
                e.getMessage());
    } catch (final TransportException e) {
        throw new GitWrapException("Transport error while fetching remote: %s. Error was: %s", e, remoteName,
                e.getMessage());
    } finally {
        if (transport != null) {
            transport.close();
        }
    }

    return this;
}

From source file:org.eclipse.egit.core.op.CloneOperation.java

License:Open Source License

private void doFetch(final IProgressMonitor monitor) throws NotSupportedException, TransportException {
    final Transport tn = Transport.open(local, remoteConfig);
    if (credentialsProvider != null)
        tn.setCredentialsProvider(credentialsProvider);
    tn.setTimeout(this.timeout);
    try {//  ww  w  .  j  ava 2  s  .  c  o  m
        final EclipseGitProgressTransformer pm;
        pm = new EclipseGitProgressTransformer(monitor);
        fetchResult = tn.fetch(pm, null);
    } finally {
        tn.close();
    }
}

From source file:org.eclipse.egit.ui.internal.fetch.FetchConfiguredRemoteAction.java

License:Open Source License

/**
 * Runs this action/* www  .  j av  a2s  . co  m*/
 * <p>
 *
 * @param shell
 *            a shell may be null; if provided, a pop up will be displayed
 *            indicating the fetch result; if Exceptions occur, these will
 *            be displayed
 *
 */
public void run(final Shell shell) {
    final RemoteConfig config;
    Exception prepareException = null;
    final Transport transport;
    try {
        config = new RemoteConfig(repository.getConfig(), remoteName);
        if (config.getURIs().isEmpty()) {
            throw new IOException(
                    NLS.bind(UIText.FetchConfiguredRemoteAction_NoUrisDefinedMessage, remoteName));
        }
        if (config.getFetchRefSpecs().isEmpty()) {
            throw new IOException(
                    NLS.bind(UIText.FetchConfiguredRemoteAction_NoSpecsDefinedMessage, remoteName));
        }
        transport = Transport.open(repository, config);
    } catch (URISyntaxException e) {
        prepareException = e;
        return;
    } catch (IOException e) {
        prepareException = e;
        return;
    } finally {
        if (prepareException != null)
            Activator.handleError(prepareException.getMessage(), prepareException, shell != null);
    }

    Job job = new Job(
            "Fetch from " + repository.getDirectory().getParentFile().getName() + " - " + remoteName) { //$NON-NLS-1$ //$NON-NLS-2$

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final FetchResult result;
            Exception fetchException = null;
            try {
                result = transport.fetch(new EclipseGitProgressTransformer(monitor), config.getFetchRefSpecs());
            } catch (final NotSupportedException e) {
                fetchException = e;
                return new Status(IStatus.ERROR, Activator.getPluginId(), UIText.FetchWizard_fetchNotSupported,
                        e);
            } catch (final TransportException e) {
                if (monitor.isCanceled())
                    return Status.CANCEL_STATUS;
                fetchException = e;
                return new Status(IStatus.ERROR, Activator.getPluginId(), UIText.FetchWizard_transportError, e);
            } finally {
                if (fetchException != null)
                    Activator.handleError(fetchException.getMessage(), fetchException, shell != null);
            }
            if (shell != null) {
                PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        Dialog dialog = new FetchResultDialog(shell, repository, result,
                                repository.getDirectory().getParentFile().getName() + " - " + remoteName); //$NON-NLS-1$
                        dialog.open();
                    }
                });
            }
            return Status.OK_STATUS;
        }

    };

    job.setUser(true);
    job.schedule();
}

From source file:org.jboss.forge.git.Clone.java

License:Eclipse Distribution License

private FetchResult runFetch() throws NotSupportedException, URISyntaxException, TransportException {
    final Transport tn = Transport.open(db, remoteName);
    final FetchResult r;
    try {// w ww.j  a  v a2  s  .  co  m
        tn.setTagOpt(TagOpt.FETCH_TAGS);
        r = tn.fetch(new TextProgressMonitor(), null);
    } finally {
        tn.close();
    }
    return r;
}

From source file:org.nbgit.ui.clone.CloneAction.java

License:Open Source License

public static FetchResult doFetch(Repository repo, OutputLogger logger)
        throws NotSupportedException, TransportException, URISyntaxException {
    final FetchResult r;
    final Transport tn = Transport.open(repo, "origin");
    try {/*from w w  w  . j av  a  2  s .co m*/
        r = tn.fetch(new GitProgressMonitor(), null);
    } finally {
        tn.close();
    }
    logger.output("--- Fetch Completed ---");
    return r;
}

From source file:org.openengsb.connector.git.internal.GitServiceImpl.java

License:Apache License

protected FetchResult doRemoteUpdate() throws IOException {
    List<RemoteConfig> remoteConfig = null;
    try {/*from w w  w .  j  a  v  a  2s  .  c  o m*/
        LOGGER.debug("Fetching remote configurations from repository configuration");
        remoteConfig = RemoteConfig.getAllRemoteConfigs(repository.getConfig());
    } catch (URISyntaxException e) {
        throw new ScmException(e);
    }

    LOGGER.debug("Opening transport to {}", remoteConfig.get(0).getName());
    Transport transport = Transport.open(repository, remoteConfig.get(0));
    try {
        LOGGER.debug("Fetching content from remote repository");
        return transport.fetch(NullProgressMonitor.INSTANCE, null);
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
}