use of org.eclipse.jgit.transport.RemoteRefUpdate in project egit by eclipse.
the class PushOperationResult method deriveSpecification.
/**
* Derive push operation specification from this push operation result.
* <p>
* Specification is created basing on URIs of remote repositories in this
* result that completed without connection errors, and remote ref updates
* from push results.
* <p>
* This method is targeted to provide support for 2-stage push, where first
* operation is dry run for user confirmation and second one is a real
* operation.
*
* @param requireUnchanged
* if true, newly created copies of remote ref updates have
* expected old object id set to previously advertised ref value
* (remote ref won't be updated if it change in the mean time),
* if false, newly create copies of remote ref updates have
* expected object id set up as in this result source
* specification.
* @return derived specification for another push operation.
* @throws IOException
* when some previously locally available source ref is not
* available anymore, or some error occurred during creation
* locally tracking ref update.
*/
public PushOperationSpecification deriveSpecification(final boolean requireUnchanged) throws IOException {
final PushOperationSpecification spec = new PushOperationSpecification();
for (final URIish uri : getURIs()) {
final PushResult pr = getPushResult(uri);
if (pr == null)
continue;
final Collection<RemoteRefUpdate> oldUpdates = pr.getRemoteUpdates();
final ArrayList<RemoteRefUpdate> newUpdates = new ArrayList<RemoteRefUpdate>(oldUpdates.size());
for (final RemoteRefUpdate rru : oldUpdates) {
final ObjectId expectedOldObjectId;
if (requireUnchanged) {
final Ref advertisedRef = getPushResult(uri).getAdvertisedRef(rru.getRemoteName());
if (advertisedRef == null)
expectedOldObjectId = ObjectId.zeroId();
else
expectedOldObjectId = advertisedRef.getObjectId();
} else
expectedOldObjectId = rru.getExpectedOldObjectId();
final RemoteRefUpdate newRru = new RemoteRefUpdate(rru, expectedOldObjectId);
newUpdates.add(newRru);
}
spec.addURIRefUpdates(uri, newUpdates);
}
return spec;
}
use of org.eclipse.jgit.transport.RemoteRefUpdate 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.jgit.transport.RemoteRefUpdate in project egit by eclipse.
the class PushToGerritPage method doPush.
void doPush() {
try {
URIish uri = new URIish(uriCombo.getText());
Ref currentHead = repository.exactRef(Constants.HEAD);
String ref = prefixCombo.getItem(prefixCombo.getSelectionIndex()) + branchText.getText().trim();
if (topicText.isEnabled()) {
ref = setTopicInRef(ref, topicText.getText().trim());
}
RemoteRefUpdate update = new RemoteRefUpdate(repository, currentHead, ref, false, null, null);
PushOperationSpecification spec = new PushOperationSpecification();
spec.addURIRefUpdates(uri, Arrays.asList(update));
final PushOperationUI op = new PushOperationUI(repository, spec, false);
storeLastUsedUri(uriCombo.getText());
storeLastUsedBranch(branchText.getText());
storeLastUsedTopic(topicText.isEnabled(), topicText.getText().trim(), repository.getBranch());
op.setPushMode(PushMode.GERRIT);
op.start();
} catch (URISyntaxException | IOException e) {
Activator.handleError(e.getMessage(), e, true);
}
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForReview.
private static void pushForReview(TestRepository<?> testRepo, RemoteRefUpdate.Status expectedStatus, String expectedMessage) throws GitAPIException {
String ref = "refs/for/master";
PushResult r = pushHead(testRepo, ref);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(ref);
assertThat(refUpdate.getStatus()).isEqualTo(expectedStatus);
if (expectedMessage != null) {
assertThat(refUpdate.getMessage()).contains(expectedMessage);
}
}
use of org.eclipse.jgit.transport.RemoteRefUpdate in project gerrit by GerritCodeReview.
the class AbstractPushForReview method errorMessageFormat.
@Test
public void errorMessageFormat() throws Exception {
RevCommit c = createCommit(testRepo, "Message without Change-Id");
assertThat(GitUtil.getChangeId(testRepo, c)).isEmpty();
String ref = "refs/for/master";
PushResult r = pushHead(testRepo, ref);
RemoteRefUpdate refUpdate = r.getRemoteUpdate(ref);
assertThat(refUpdate.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
String reason = String.format("commit %s: missing Change-Id in message footer", abbreviateName(c));
assertThat(refUpdate.getMessage()).isEqualTo(reason);
assertThat(r.getMessages()).contains("\nERROR: " + reason);
}
Aggregations