List of usage examples for org.eclipse.jgit.transport Transport findRemoteRefUpdatesFor
public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(final Repository db, final Collection<RefSpec> specs, Collection<RefSpec> fetchSpecs) throws IOException
From source file:com.genuitec.eclipse.gerrit.tools.internal.fbranches.BranchingUtils.java
License:Open Source License
public static PushOperationSpecification setupPush(Repository repository, String refSpec) throws IOException, URISyntaxException { PushOperationSpecification spec = new PushOperationSpecification(); Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(repository, Collections.singletonList(new RefSpec(refSpec)), null); RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); for (URIish uri : config.getPushURIs()) { spec.addURIRefUpdates(uri, updates); break;//from w w w . j a v a 2 s .co m } if (spec.getURIsNumber() == 0) { for (URIish uri : config.getURIs()) { spec.addURIRefUpdates(uri, updates); break; } } if (spec.getURIsNumber() == 0) { throw new RuntimeException("Cannot find URI for push"); } return spec; }
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository push(final String name) throws GitWrapException { try {/*from w w w.j a va2s . com*/ 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.ui.internal.push.ConfirmationPage.java
License:Open Source License
private void revalidateImpl() { if (getControl().isDisposed() || !isCurrentPage()) return;// w w w . j a va2s .c om final List<RefSpec> fetchSpecs; if (displayedRepoSelection.isConfigSelected()) fetchSpecs = displayedRepoSelection.getConfig().getPushRefSpecs(); 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, displayedRepoSelection.getConfig(), timeout); if (credentials != null) operation.setCredentialsProvider( new UsernamePasswordCredentialsProvider(credentials.getUser(), credentials.getPassword())); getContainer().run(true, true, new IRunnableWithProgress() { 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)); } }
From source file:org.eclipse.egit.ui.internal.push.PushConfiguredRemoteAction.java
License:Open Source License
/** * Runs this action/*from w w w .ja va 2 s . c o m*/ * <p> * * @param shell * a shell may be null; if provided, a pop up will be displayed * indicating the fetch result * @param dryRun * */ public void run(final Shell shell, boolean dryRun) { RemoteConfig config; PushOperationSpecification spec; Exception pushException = null; final PushOperation op; try { config = new RemoteConfig(repository.getConfig(), remoteName); // config.getPushURIs returns a unmodifiable list List<URIish> pushURIs = new ArrayList<URIish>(); pushURIs.addAll(config.getPushURIs()); if (pushURIs.isEmpty() && !config.getURIs().isEmpty()) pushURIs.add(config.getURIs().get(0)); if (pushURIs.isEmpty()) { throw new IOException(NLS.bind(UIText.PushConfiguredRemoteAction_NoUrisMessage, remoteName)); } final Collection<RefSpec> pushSpecs = config.getPushRefSpecs(); if (pushSpecs.isEmpty()) { throw new IOException(NLS.bind(UIText.PushConfiguredRemoteAction_NoSpecDefined, remoteName)); } final Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(repository, pushSpecs, null); if (updates.isEmpty()) { throw new IOException( NLS.bind(UIText.PushConfiguredRemoteAction_NoUpdatesFoundMessage, remoteName)); } spec = new PushOperationSpecification(); for (final URIish uri : pushURIs) spec.addURIRefUpdates(uri, ConfirmationPage.copyUpdates(updates)); int timeout = Activator.getDefault().getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); op = new PushOperation(repository, spec, dryRun, config, timeout); } catch (URISyntaxException e) { pushException = e; return; } catch (IOException e) { pushException = e; return; } finally { if (pushException != null) Activator.handleError(pushException.getMessage(), pushException, shell != null); } final Job job = new Job( "Push to " + repository.getDirectory().getParentFile().getName() + " - " + remoteName) { //$NON-NLS-1$ //$NON-NLS-2$ @Override protected IStatus run(IProgressMonitor monitor) { try { op.run(monitor); final PushOperationResult res = op.getOperationResult(); if (shell != null) { PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { final Dialog dialog = new PushResultDialog(shell, repository, res, repository.getDirectory().getParentFile().getName() + " - " + remoteName); //$NON-NLS-1$ dialog.open(); } }); } return Status.OK_STATUS; } catch (InvocationTargetException e) { return new Status(IStatus.ERROR, Activator.getPluginId(), e.getCause().getMessage(), e); } } @Override public boolean belongsTo(Object family) { if (family.equals(JobFamilies.PUSH)) return true; return super.belongsTo(family); } }; job.setUser(true); job.schedule(); }
From source file:org.eclipse.egit.ui.internal.push.PushOperationUI.java
License:Open Source License
private void createPushOperation() throws CoreException { if (remoteName != null) { op = new PushOperation(repository, remoteName, dryRun, timeout); return;/*from w w w.j a va 2 s. c o m*/ } 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<URIish>(); 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<RefSpec>(); 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, timeout); }
From source file:org.eclipse.egit.ui.internal.push.PushWizard.java
License:Open Source License
private PushOperation createPushOperation() { try {/* w w w.j a v a 2 s .com*/ final PushOperationSpecification spec; final RemoteConfig config = repoPage.getSelection().getConfig(); if (confirmPage.isConfirmed()) { final PushOperationResult confirmedResult = confirmPage.getConfirmedResult(); spec = confirmedResult.deriveSpecification(confirmPage.isRequireUnchangedSelected()); } else { final Collection<RefSpec> fetchSpecs; if (config != null) fetchSpecs = config.getPushRefSpecs(); 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, config, 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; } }
From source file:org.eclipse.egit.ui.internal.push.SimplePushRefWizard.java
License:Open Source License
@Override public boolean performFinish() { try {//w w w. jav a 2s . co m int timeout = Activator.getDefault().getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); PushOperationSpecification specification = new PushOperationSpecification(); RepositorySelection remote = repoPage.getSelection(); RefSpec refSpec = new RefSpec().setSourceDestination(pushObj.name(), targetPage.getTargetRef()) .setForceUpdate(targetPage.isForceUpdate()); // Include fetchSpecs in calculation so that tracking refs are also updated RemoteConfig remoteConfig = remote.getConfig(); List<RefSpec> fetchSpecs = remoteConfig != null ? remoteConfig.getFetchRefSpecs() : null; Collection<RemoteRefUpdate> remoteRefUpdates = Transport.findRemoteRefUpdatesFor(repo, Collections.singleton(refSpec), fetchSpecs); specification.addURIRefUpdates(remote.getURI(true), remoteRefUpdates); PushOperation pop = new PushOperation(repo, specification, false, timeout); PushJob job = new PushWizard.PushJob(repo, pop, null, PushWizard.getDestinationString(remote)); job.setUser(true); job.schedule(); repoPage.saveUriInPrefs(); } catch (Exception e) { Activator.handleError(e.getMessage(), e, true); } return true; }