List of usage examples for org.eclipse.jgit.transport RemoteRefUpdate RemoteRefUpdate
public RemoteRefUpdate(final RemoteRefUpdate base, final ObjectId newExpectedOldObjectId) throws IOException
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository push(final String name) throws GitWrapException { try {// ww w . j av a2s . c o m final StoredConfig config = repository.getConfig(); final RemoteConfig remote = new RemoteConfig(config, name); final List<URIish> pushURIs = remote.getPushURIs(); final List<RefSpec> pushRefSpecs = remote.getPushRefSpecs(); final Collection<RemoteRefUpdate> remoteRefUpdates = Transport.findRemoteRefUpdatesFor(repository, pushRefSpecs, null); for (final URIish uri : pushURIs) { final Collection<RemoteRefUpdate> updates = new ArrayList<RemoteRefUpdate>(); for (final RemoteRefUpdate rru : remoteRefUpdates) { updates.add(new RemoteRefUpdate(rru, null)); } Transport transport = null; try { transport = Transport.open(repository, uri); transport.applyConfig(remote); final PushResult result = transport.push(MONITOR, updates); if (result.getMessages().length() > 0 && LOGGER.isDebugEnabled()) { LOGGER.debug(result.getMessages()); } } finally { if (transport != null) { transport.close(); } } } } catch (final NotSupportedException e) { throw new GitWrapException( "Cannot push to repository: %s. Transport is not supported.\nNested error: %s", e, name, e.getMessage()); } catch (final TransportException e) { throw new GitWrapException("Transport failed for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } catch (final URISyntaxException e) { throw new GitWrapException("Invalid URI for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } catch (final IOException e) { throw new GitWrapException("Transport failed for repository push: %s.\nNested error: %s", e, name, e.getMessage()); } return this; }
From source file:org.eclipse.egit.core.op.PushOperationResult.java
License:Open Source License
/** * Derive push operation specification from this push operation result. * <p>/*from ww w.j av a 2 s .com*/ * 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; }
From source file:org.eclipse.egit.ui.internal.push.ConfirmationPage.java
License:Open Source License
static Collection<RemoteRefUpdate> copyUpdates(final Collection<RemoteRefUpdate> refUpdates) throws IOException { final Collection<RemoteRefUpdate> copy = new ArrayList<RemoteRefUpdate>(refUpdates.size()); for (final RemoteRefUpdate rru : refUpdates) copy.add(new RemoteRefUpdate(rru, null)); return copy;//www. j av a2 s . c om }