Search in sources :

Example 6 with PushOperation

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

the class CurrentBranchPublishOperation method execute.

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    try {
        PushOperation pushOperation = new PushOperation(repository.getRepository(), DEFAULT_REMOTE_NAME, false, // TODO: check if multiple remotes exist? There is no explicit refspec?
        timeout);
        pushOperation.run(monitor);
        operationResult = pushOperation.getOperationResult();
        if (!operationResult.isSuccessfulConnectionForAnyURI()) {
            String errorMessage = NLS.bind(CoreText.pushToRemoteFailed, operationResult.getErrorStringForAllURis());
            throw new CoreException(error(errorMessage));
        }
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        throw new CoreException(error(targetException.getMessage(), targetException));
    }
    String newLocalBranch = getCurrentBranchhName();
    try {
        repository.setRemote(newLocalBranch, DEFAULT_REMOTE_NAME);
        repository.setUpstreamBranchName(newLocalBranch, repository.getRepository().getFullBranch());
    } catch (IOException e) {
        throw new CoreException(error(CoreText.unableToStoreGitConfig, e));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) PushOperation(org.eclipse.egit.core.op.PushOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with PushOperation

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

the class PushWizard method createPushOperation.

private PushOperation createPushOperation(boolean calledFromRepoPage) {
    try {
        final PushOperationSpecification spec;
        final RemoteConfig config = repoPage.getSelection().getConfig();
        if (calledFromRepoPage) {
            // obtain the push ref specs from the configuration
            // use our own list here, as the config returns a non-modifiable
            // list
            final Collection<RefSpec> pushSpecs = new ArrayList<>();
            pushSpecs.addAll(config.getPushRefSpecs());
            final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(localDb, pushSpecs, config.getFetchRefSpecs());
            spec = new PushOperationSpecification();
            for (final URIish uri : repoPage.getSelection().getPushURIs()) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
        } else if (confirmPage.isConfirmed()) {
            final PushOperationResult confirmedResult = confirmPage.getConfirmedResult();
            spec = confirmedResult.deriveSpecification(confirmPage.isRequireUnchangedSelected());
        } else {
            final Collection<RefSpec> fetchSpecs;
            if (config != null)
                fetchSpecs = config.getFetchRefSpecs();
            else
                fetchSpecs = null;
            final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(localDb, refSpecPage.getRefSpecs(), fetchSpecs);
            if (updates.isEmpty()) {
                ErrorDialog.openError(getShell(), UIText.PushWizard_missingRefsTitle, null, new Status(IStatus.ERROR, Activator.getPluginId(), UIText.PushWizard_missingRefsMessage));
                return null;
            }
            spec = new PushOperationSpecification();
            for (final URIish uri : repoPage.getSelection().getPushURIs()) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates));
        }
        int timeout = Activator.getDefault().getPreferenceStore().getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT);
        return new PushOperation(localDb, spec, false, timeout);
    } catch (final IOException e) {
        ErrorDialog.openError(getShell(), UIText.PushWizard_cantPrepareUpdatesTitle, UIText.PushWizard_cantPrepareUpdatesMessage, new Status(IStatus.ERROR, Activator.getPluginId(), e.getMessage(), e));
        return null;
    }
}
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) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PushOperation(org.eclipse.egit.core.op.PushOperation) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Example 8 with PushOperation

use of org.eclipse.egit.core.op.PushOperation 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 9 with PushOperation

use of org.eclipse.egit.core.op.PushOperation 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 10 with PushOperation

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

Aggregations

PushOperation (org.eclipse.egit.core.op.PushOperation)14 URIish (org.eclipse.jgit.transport.URIish)9 PushOperationSpecification (org.eclipse.egit.core.op.PushOperationSpecification)8 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)7 PushOperationResult (org.eclipse.egit.core.op.PushOperationResult)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 RefSpec (org.eclipse.jgit.transport.RefSpec)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 CoreException (org.eclipse.core.runtime.CoreException)3 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Status (org.eclipse.core.runtime.Status)2 EGitCredentialsProvider (org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider)2 NotSupportedException (org.eclipse.jgit.errors.NotSupportedException)2 MalformedURLException (java.net.MalformedURLException)1