Search in sources :

Example 1 with ListRemoteOperation

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

the class FetchSourcePage method getRemoteRefs.

private List<Ref> getRemoteRefs() {
    if (remoteRefs == null) {
        URIish uriToCheck;
        List<Ref> proposals = new ArrayList<>();
        uriToCheck = config.getURIs().get(0);
        final ListRemoteOperation lop = new ListRemoteOperation(repository, uriToCheck, Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT));
        try {
            new ProgressMonitorDialog(getShell()).run(true, true, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    monitor.beginTask(UIText.FetchSourcePage_GettingRemoteRefsTaskname, IProgressMonitor.UNKNOWN);
                    lop.run(monitor);
                    monitor.done();
                }
            });
            for (Ref ref : lop.getRemoteRefs()) {
                if (ref.getName().startsWith(Constants.R_HEADS) || ref.getName().startsWith(Constants.R_TAGS))
                    proposals.add(ref);
            }
            Collections.sort(proposals, new Comparator<Ref>() {

                @Override
                public int compare(Ref o1, Ref o2) {
                    return o1.getName().compareTo(o2.getName());
                }
            });
            this.remoteRefs = proposals;
        } catch (IllegalStateException e) {
            setErrorMessage(e.getMessage());
        } catch (InvocationTargetException e) {
            setErrorMessage(e.getMessage());
        } catch (InterruptedException e) {
            setErrorMessage(e.getMessage());
        }
    }
    return remoteRefs;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) Ref(org.eclipse.jgit.lib.Ref) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 2 with ListRemoteOperation

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

the class ListRemoteOperationTest method testIllegalURI.

/**
 * Test with illegal URI
 *
 * @throws Exception
 */
@Test
public void testIllegalURI() throws Exception {
    URIish uri = new URIish("file:///" + "no/path");
    ListRemoteOperation lrop = new ListRemoteOperation(repository1.getRepository(), uri, 0);
    try {
        lrop.run(new NullProgressMonitor());
        fail("Expected Exception not thrown");
    } catch (InvocationTargetException e) {
    // expected
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 3 with ListRemoteOperation

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

the class ListRemoteOperationTest method testIllegalStateException.

/**
 * Call getRemoteRefs without having run the op
 *
 * @throws Exception
 */
@Test
public void testIllegalStateException() throws Exception {
    URIish uri = new URIish("file:///" + repository2.getRepository().getDirectory().getPath());
    ListRemoteOperation lrop = new ListRemoteOperation(repository1.getRepository(), uri, 0);
    try {
        lrop.getRemoteRefs();
        fail("Expected Exception not thrown");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) Test(org.junit.Test)

Example 4 with ListRemoteOperation

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

the class ListRemoteOperationTest method testListRemote.

/**
 * List the refs both ways
 *
 * @throws Exception
 */
@Test
public void testListRemote() throws Exception {
    URIish uri = new URIish("file:///" + repository2.getRepository().getDirectory().getPath());
    ListRemoteOperation lrop = new ListRemoteOperation(repository1.getRepository(), uri, 0);
    lrop.run(null);
    assertEquals(4, lrop.getRemoteRefs().size());
    assertNotNull(lrop.getRemoteRef("refs/heads/test"));
    uri = new URIish("file:///" + repository1.getRepository().getDirectory().getPath());
    lrop = new ListRemoteOperation(repository2.getRepository(), uri, 0);
    lrop.run(new NullProgressMonitor());
    assertEquals(2, lrop.getRemoteRefs().size());
    assertNotNull(lrop.getRemoteRef("refs/heads/master"));
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Test(org.junit.Test)

Example 5 with ListRemoteOperation

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

the class RefSpecPage method revalidateImpl.

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

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                listRemotesOp.run(monitor);
            }
        });
    } catch (InvocationTargetException e) {
        final Throwable cause = e.getCause();
        transportError(cause.getMessage());
        Activator.handleError(UIText.RefSpecPage_errorTransportDialogMessage, cause, true);
        return;
    } catch (InterruptedException e) {
        transportError(UIText.RefSpecPage_operationCancelled);
        return;
    }
    this.validatedRepoSelection = newRepoSelection;
    specsPanel.setAssistanceData(local, listRemotesOp.getRemoteRefs(), currentRepoSelection.getConfig());
    if (newRepoSelection.isConfigSelected()) {
        saveButton.setVisible(true);
        saveButton.setText(NLS.bind(UIText.RefSpecPage_saveSpecifications, currentRepoSelection.getConfigName()));
        saveButton.getParent().layout();
        if (!pushPage) {
            tagsAutoFollowButton.setSelection(false);
            tagsFetchTagsButton.setSelection(false);
            tagsNoTagsButton.setSelection(false);
            final TagOpt tagOpt = newRepoSelection.getConfig().getTagOpt();
            switch(tagOpt) {
                case AUTO_FOLLOW:
                    tagsAutoFollowButton.setSelection(true);
                    break;
                case FETCH_TAGS:
                    tagsFetchTagsButton.setSelection(true);
                    break;
                case NO_TAGS:
                    tagsNoTagsButton.setSelection(true);
                    break;
            }
        }
    } else if (!pushPage)
        tagsAutoFollowButton.setSelection(true);
    checkPage();
}
Also used : URIish(org.eclipse.jgit.transport.URIish) ListRemoteOperation(org.eclipse.egit.core.op.ListRemoteOperation) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TagOpt(org.eclipse.jgit.transport.TagOpt) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) 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