Search in sources :

Example 6 with ListRemoteOperation

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

the class FeatureListOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    String uriString = FILE + repository.getRepository().getDirectory().getPath();
    try {
        operationResult = fetch(progress.newChild(1), timeout);
        URIish uri = new URIish(uriString);
        ListRemoteOperation listRemoteOperation = new ListRemoteOperation(repository.getRepository(), uri, timeout);
        listRemoteOperation.run(progress.newChild(1));
        Collection<Ref> remoteRefs = listRemoteOperation.getRemoteRefs();
        for (Ref ref : remoteRefs) {
            if (ref.getName().startsWith(REMOTE_ORIGIN_FEATURE_PREFIX + repository.getConfig().getFeaturePrefix())) {
                result.add(ref);
            }
        }
    } catch (URISyntaxException e) {
        String message = NLS.bind(CoreText.FeatureListOperation_unableToParse, uriString);
        throw new CoreException(error(message, e));
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        throw new CoreException(error(targetException.getMessage(), targetException));
    } catch (InterruptedException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) Ref(org.eclipse.jgit.lib.Ref) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) URISyntaxException(java.net.URISyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with ListRemoteOperation

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

the class SourceBranchPage method revalidateImpl.

private void revalidateImpl(final RepositorySelection newRepoSelection) {
    if (label.isDisposed() || !isCurrentPage())
        return;
    final ListRemoteOperation listRemoteOp;
    final URIish uri = newRepoSelection.getURI();
    try {
        int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
        listRemoteOp = new ListRemoteOperation(uri, timeout);
        if (credentials != null)
            listRemoteOp.setCredentialsProvider(new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword()));
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                listRemoteOp.run(monitor);
            }
        });
    } catch (InvocationTargetException e) {
        Throwable why = e.getCause();
        transportError(why);
        if (showDetailedFailureDialog())
            SourceBranchFailureDialog.show(getShell(), uri);
        return;
    } catch (InterruptedException e) {
        transportError(UIText.SourceBranchPage_remoteListingCancelled);
        return;
    }
    final Ref idHEAD = listRemoteOp.getRemoteRef(Constants.HEAD);
    head = null;
    boolean headIsMaster = false;
    final String masterBranchRef = Constants.R_HEADS + Constants.MASTER;
    for (final Ref r : listRemoteOp.getRemoteRefs()) {
        final String n = r.getName();
        if (!n.startsWith(Constants.R_HEADS)) {
            continue;
        }
        availableRefs.add(r);
        if (idHEAD == null || headIsMaster) {
            continue;
        }
        ObjectId objectId = r.getObjectId();
        if (objectId == null) {
            continue;
        }
        if (objectId.equals(idHEAD.getObjectId())) {
            headIsMaster = masterBranchRef.equals(r.getName());
            if (head == null || headIsMaster) {
                head = r;
            }
        }
    }
    Collections.sort(availableRefs, new Comparator<Ref>() {

        @Override
        public int compare(final Ref o1, final Ref o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
        }
    });
    if (idHEAD != null && head == null) {
        head = idHEAD;
        availableRefs.add(0, idHEAD);
    }
    validatedRepoSelection = newRepoSelection;
    refsViewer.setInput(availableRefs);
    refsViewer.setAllChecked(true);
    checkPage();
    checkForEmptyRepo();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ObjectId(org.eclipse.jgit.lib.ObjectId) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Ref(org.eclipse.jgit.lib.Ref)

Example 8 with ListRemoteOperation

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

the class LocalRepositoryTestCase method getRemoteRefs.

protected static Collection<Ref> getRemoteRefs(URIish uri) throws Exception {
    int timeout = 20;
    ListRemoteOperation listRemoteOp = new ListRemoteOperation(uri, timeout);
    listRemoteOp.run(null);
    return listRemoteOp.getRemoteRefs();
}
Also used : ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation)

Example 9 with ListRemoteOperation

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

the class RefContentAssistProvider method getRefsForContentAssist.

/**
 * @param source whether we want proposals for the source or the destination of the operation
 * @param pushMode whether the operation is a push or a fetch
 * @return a list of all refs for the given mode.
 */
public List<Ref> getRefsForContentAssist(boolean source, boolean pushMode) {
    if (source) {
        if (sourceRefs != null)
            return sourceRefs;
    } else if (destinationRefs != null)
        return destinationRefs;
    List<Ref> result = new ArrayList<>();
    try {
        boolean local = pushMode == source;
        if (!local) {
            final ListRemoteOperation lop = new ListRemoteOperation(repo, uri, Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT));
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(UIText.RefSpecDialog_GettingRemoteRefsMonitorMessage, IProgressMonitor.UNKNOWN);
                    lop.run(monitor);
                    monitor.done();
                }
            };
            if (shell != null) {
                new ProgressMonitorDialog(shell).run(true, true, runnable);
            } else {
                container.run(true, true, runnable);
            }
            for (Ref ref : lop.getRemoteRefs()) if (ref.getName().startsWith(Constants.R_HEADS) || (!pushMode && ref.getName().startsWith(Constants.R_TAGS)))
                result.add(ref);
        } else if (pushMode)
            for (Ref ref : repo.getRefDatabase().getRefs(RefDatabase.ALL).values()) {
                if (ref.getName().startsWith(Constants.R_REMOTES))
                    continue;
                result.add(ref);
            }
        else
            for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_REMOTES).values()) result.add(ref);
    } catch (RuntimeException e) {
        throw e;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        Activator.handleError(cause.getMessage(), cause, true);
        return result;
    } catch (Exception e) {
        Activator.handleError(e.getMessage(), e, true);
        return result;
    }
    Collections.sort(result, CommonUtils.REF_ASCENDING_COMPARATOR);
    if (source)
        sourceRefs = result;
    else
        destinationRefs = result;
    return result;
}
Also used : ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) Ref(org.eclipse.jgit.lib.Ref) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ListRemoteOperation (org.eclipse.egit.core.op.ListRemoteOperation)9 URIish (org.eclipse.jgit.transport.URIish)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 Ref (org.eclipse.jgit.lib.Ref)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 URISyntaxException (java.net.URISyntaxException)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 TagOpt (org.eclipse.jgit.transport.TagOpt)1