Search in sources :

Example 11 with PushOperation

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

the class PushOperationTest method testPushWithReusedSpec.

/**
 * We should get an {@link IllegalStateException} if the spec was re-used
 *
 * @throws Exception
 */
@Test
public void testPushWithReusedSpec() throws Exception {
    PushOperationSpecification spec = new PushOperationSpecification();
    // the remote is repo2
    URIish remote = repository2.getUri();
    // update master upon master
    List<RemoteRefUpdate> refUpdates = new ArrayList<RemoteRefUpdate>();
    RemoteRefUpdate update = new RemoteRefUpdate(repository1.getRepository(), "HEAD", "refs/heads/test", false, null, null);
    refUpdates.add(update);
    spec.addURIRefUpdates(remote, refUpdates);
    PushOperation pop = new PushOperation(repository1.getRepository(), spec, false, 0);
    pop.run(null);
    pop = new PushOperation(repository1.getRepository(), spec, false, 0);
    try {
        pop.run(null);
        fail("Expected Exception not thrown");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ArrayList(java.util.ArrayList) PushOperationSpecification(org.eclipse.egit.core.op.PushOperationSpecification) PushOperation(org.eclipse.egit.core.op.PushOperation) Test(org.junit.Test)

Example 12 with PushOperation

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

the class PushOperationTest method testPush.

/**
 * Push from repository1 "master" into "test" of repository2.
 *
 * @throws Exception
 */
@Test
public void testPush() throws Exception {
    // push from repository1 to repository2
    PushOperation pop = createPushOperation();
    pop.run(new NullProgressMonitor());
    assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
    // let's add a new file to the project shared with repository1
    IProject proj = importProject(repository1, projectName);
    ArrayList<IFile> files = new ArrayList<IFile>();
    IFile newFile = testUtils.addFileToProject(proj, "folder2/file2.txt", "New file");
    files.add(newFile);
    IFile[] fileArr = files.toArray(new IFile[files.size()]);
    AddToIndexOperation trop = new AddToIndexOperation(files);
    trop.execute(null);
    CommitOperation cop = new CommitOperation(fileArr, files, TestUtils.AUTHOR, TestUtils.COMMITTER, "Added file");
    cop.execute(null);
    proj.delete(false, false, null);
    pop = createPushOperation();
    pop.run(null);
    assertEquals(Status.OK, getStatus(pop.getOperationResult()));
    try {
        // assert that we cannot run this again
        pop.run(null);
        fail("Expected Exception not thrown");
    } catch (IllegalStateException e) {
    // expected
    }
    pop = createPushOperation();
    pop.run(null);
    assertEquals(Status.UP_TO_DATE, getStatus(pop.getOperationResult()));
    String newFilePath = newFile.getFullPath().toOSString();
    File testFile = new File(workdir2, newFilePath);
    assertFalse(testFile.exists());
    testFile = new File(workdir, newFilePath);
    assertTrue(testFile.exists());
    // check out test and verify the file is there
    BranchOperation bop = new BranchOperation(repository2.getRepository(), "refs/heads/test");
    bop.execute(null);
    testFile = new File(workdir2, newFilePath);
    assertTrue(testFile.exists());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) BranchOperation(org.eclipse.egit.core.op.BranchOperation) ArrayList(java.util.ArrayList) PushOperation(org.eclipse.egit.core.op.PushOperation) IProject(org.eclipse.core.resources.IProject) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Example 13 with PushOperation

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

Example 14 with PushOperation

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

the class PushWizard method performFinish.

@Override
public boolean performFinish() {
    boolean calledFromRepoPage = false;
    if (getContainer().getCurrentPage() == repoPage)
        calledFromRepoPage = true;
    if (repoPage.getSelection().isConfigSelected() && refSpecPage.isSaveRequested()) {
        saveRefSpecs();
    }
    if (repoPage.getStoreInSecureStore()) {
        if (!SecureStoreUtils.storeCredentials(repoPage.getCredentials(), repoPage.getSelection().getURI()))
            return false;
    }
    final PushOperation operation = createPushOperation(calledFromRepoPage);
    if (operation == null)
        return false;
    UserPasswordCredentials credentials = repoPage.getCredentials();
    if (credentials != null)
        operation.setCredentialsProvider(new EGitCredentialsProvider(credentials.getUser(), credentials.getPassword()));
    final PushOperationResult resultToCompare;
    if (confirmPage.isShowOnlyIfChangedSelected()) {
        resultToCompare = confirmPage.getConfirmedResult();
    } else {
        resultToCompare = null;
    }
    final Job job = new PushJob(NLS.bind(UIText.PushWizard_jobName, getURIsString(operation.getSpecification().getURIs())), localDb, operation, resultToCompare, getDestinationString(repoPage.getSelection()), true, PushMode.UPSTREAM);
    job.setUser(true);
    job.schedule();
    repoPage.saveUriInPrefs();
    return true;
}
Also used : PushOperationResult(org.eclipse.egit.core.op.PushOperationResult) PushOperation(org.eclipse.egit.core.op.PushOperation) Job(org.eclipse.core.runtime.jobs.Job) EGitCredentialsProvider(org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider) UserPasswordCredentials(org.eclipse.egit.core.securestorage.UserPasswordCredentials)

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