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
}
}
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());
}
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));
}
}
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;
}
Aggregations