Search in sources :

Example 6 with PushOperationResult

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

the class PushBranchWizard method startPush.

private void startPush() throws IOException {
    PushOperationResult result = confirmationPage.getConfirmedResult();
    PushOperationSpecification pushSpec = result.deriveSpecification(confirmationPage.isRequireUnchangedSelected());
    PushOperationUI pushOperationUI = new PushOperationUI(repository, pushSpec, false);
    pushOperationUI.setCredentialsProvider(new EGitCredentialsProvider());
    pushOperationUI.setShowConfigureButton(false);
    if (confirmationPage.isShowOnlyIfChangedSelected())
        pushOperationUI.setExpectedResult(result);
    pushOperationUI.start();
}
Also used : PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)

Example 7 with PushOperationResult

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

the class PushResultTable method getResult.

private String getResult(RefUpdateElement element) {
    StringBuilder result = new StringBuilder(EMPTY_STRING);
    PushOperationResult pushOperationResult = element.getPushOperationResult();
    final URIish uri = element.getUri();
    result.append(UIText.PushResultTable_repository);
    result.append(SPACE);
    result.append(uri.toString());
    result.append(Text.DELIMITER);
    result.append(Text.DELIMITER);
    String message = element.getRemoteRefUpdate().getMessage();
    if (message != null)
        result.append(message).append(Text.DELIMITER);
    StringBuilder messagesBuffer = new StringBuilder(pushOperationResult.getPushResult(uri).getMessages());
    trim(messagesBuffer);
    if (messagesBuffer.length() > 0)
        result.append(messagesBuffer).append(Text.DELIMITER);
    trim(result);
    return result.toString();
}
Also used : PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) URIish(org.eclipse.jgit.transport.URIish) StyledString(org.eclipse.jface.viewers.StyledString)

Example 8 with PushOperationResult

use of org.eclipse.egit.core.op.PushOperationResult in project jbosstools-openshift by jbosstools.

the class EGitUtils method push.

private static PushOperationResult push(Repository repository, RemoteConfig remoteConfig, boolean force, IProgressMonitor monitor, OutputStream out) throws CoreException {
    try {
        if (remoteConfig == null) {
            throw new CoreException(createStatus(null, "Repository \"{0}\" has no remote repository configured", repository.toString()));
        }
        PushOperation op = createPushOperation(remoteConfig, repository, force, out);
        op.run(monitor);
        PushOperationResult pushResult = op.getOperationResult();
        if (hasFailedEntries(pushResult)) {
            throw new CoreException(EGitCoreActivator.createErrorStatus(NLS.bind("Could not push repository {0}: {1}", repository.toString(), getErrors(pushResult)), null));
        }
        return pushResult;
    } catch (CoreException e) {
        throw e;
    } catch (Exception e) {
        throw new CoreException(createStatus(e, "Could not push repo {0}", repository.toString()));
    }
}
Also used : PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) CoreException(org.eclipse.core.runtime.CoreException) PushOperation(org.eclipse.egit.core.op.PushOperation) URISyntaxException(java.net.URISyntaxException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) CoreException(org.eclipse.core.runtime.CoreException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) NotSupportedException(org.eclipse.jgit.errors.NotSupportedException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException)

Example 9 with PushOperationResult

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

the class PushOperationTest method testUpdateTrackingBranchIfSpecifiedInRemoteRefUpdate.

@Test
public void testUpdateTrackingBranchIfSpecifiedInRemoteRefUpdate() throws Exception {
    // Commit on repository 2
    IProject project = importProject(repository2, projectName);
    RevCommit commit = repository2.addAndCommit(project, new File(workdir2, "test.txt"), "Commit in repository 2");
    project.delete(false, false, null);
    // We want to push from repository 2 to 1 (because repository 2 already
    // has tracking set up)
    URIish remote = repository1.getUri();
    String trackingRef = "refs/remotes/origin/master";
    RemoteRefUpdate update = new RemoteRefUpdate(repository2.getRepository(), "HEAD", "refs/heads/master", false, trackingRef, null);
    PushOperationSpecification spec = new PushOperationSpecification();
    spec.addURIRefUpdates(remote, Arrays.asList(update));
    PushOperation push = new PushOperation(repository2.getRepository(), spec, false, 0);
    push.run(null);
    PushOperationResult result = push.getOperationResult();
    PushResult pushResult = result.getPushResult(remote);
    assertNotNull("Expected result to have tracking ref update", pushResult.getTrackingRefUpdate(trackingRef));
    ObjectId trackingId = repository2.getRepository().resolve(trackingRef);
    assertEquals("Expected tracking branch to be updated", commit.getId(), trackingId);
}
Also used : URIish(org.eclipse.jgit.transport.URIish) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) ObjectId(org.eclipse.jgit.lib.ObjectId) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) PushResult(org.eclipse.jgit.transport.PushResult) PushOperation(org.eclipse.egit.core.op.PushOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 10 with PushOperationResult

use of org.eclipse.egit.core.op.PushOperationResult 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)

Aggregations

PushOperationResult (org.eclipse.egit.core.op.PushOperationResult)11 PushOperation (org.eclipse.egit.core.op.PushOperation)6 PushOperationSpecification (org.eclipse.egit.core.op.PushOperationSpecification)5 URIish (org.eclipse.jgit.transport.URIish)5 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)4 IOException (java.io.IOException)3 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)3 Test (org.junit.Test)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 PushResult (org.eclipse.jgit.transport.PushResult)2 RefSpec (org.eclipse.jgit.transport.RefSpec)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1