use of org.eclipse.egit.core.op.PushOperationSpecification 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;
}
}
use of org.eclipse.egit.core.op.PushOperationSpecification 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();
}
use of org.eclipse.egit.core.op.PushOperationSpecification 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());
}
use of org.eclipse.egit.core.op.PushOperationSpecification 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);
}
use of org.eclipse.egit.core.op.PushOperationSpecification 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
}
}
Aggregations