List of usage examples for org.eclipse.jgit.transport RemoteConfig setFetchRefSpecs
public void setFetchRefSpecs(List<RefSpec> specs)
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void remoteUpdate(RemoteUpdateRequest request) throws GitException { String remoteName = request.getName(); if (isNullOrEmpty(remoteName)) { throw new IllegalArgumentException(ERROR_UPDATE_REMOTE_NAME_MISSING); }/* w w w. j av a 2 s . co m*/ StoredConfig config = repository.getConfig(); Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE); if (!remoteNames.contains(remoteName)) { throw new IllegalArgumentException("Remote " + remoteName + " not found. "); } RemoteConfig remoteConfig; try { remoteConfig = new RemoteConfig(config, remoteName); } catch (URISyntaxException e) { throw new GitException(e.getMessage(), e); } List<String> branches = request.getBranches(); if (!branches.isEmpty()) { if (!request.isAddBranches()) { remoteConfig.setFetchRefSpecs(Collections.emptyList()); remoteConfig.setPushRefSpecs(Collections.emptyList()); } else { // Replace wildcard refSpec if any. remoteConfig.removeFetchRefSpec( new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*") .setForceUpdate(true)); remoteConfig.removeFetchRefSpec( new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*")); } // Add new refSpec. for (String branch : branches) { remoteConfig.addFetchRefSpec(new RefSpec( Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch) .setForceUpdate(true)); } } // Remove URLs first. for (String url : request.getRemoveUrl()) { try { remoteConfig.removeURI(new URIish(url)); } catch (URISyntaxException e) { LOG.debug(ERROR_REMOVING_INVALID_URL); } } // Add new URLs. for (String url : request.getAddUrl()) { try { remoteConfig.addURI(new URIish(url)); } catch (URISyntaxException e) { throw new IllegalArgumentException("Remote url " + url + " is invalid. "); } } // Remove URLs for pushing. for (String url : request.getRemovePushUrl()) { try { remoteConfig.removePushURI(new URIish(url)); } catch (URISyntaxException e) { LOG.debug(ERROR_REMOVING_INVALID_URL); } } // Add URLs for pushing. for (String url : request.getAddPushUrl()) { try { remoteConfig.addPushURI(new URIish(url)); } catch (URISyntaxException e) { throw new IllegalArgumentException("Remote push url " + url + " is invalid. "); } } remoteConfig.update(config); try { config.save(); } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.egit.ui.internal.fetch.FetchWizard.java
License:Open Source License
private void saveConfig() { final RemoteConfig rc = repoPage.getSelection().getConfig(); rc.setFetchRefSpecs(refSpecPage.getRefSpecs()); rc.setTagOpt(refSpecPage.getTagOpt()); final StoredConfig config = localDb.getConfig(); rc.update(config);//from w w w .j a v a 2s.c o m try { config.save(); } catch (final IOException e) { ErrorDialog.openError(getShell(), UIText.FetchWizard_cantSaveTitle, UIText.FetchWizard_cantSaveMessage, new Status(IStatus.WARNING, Activator.getPluginId(), e.getMessage(), e)); // Continue, it's not critical. } }
From source file:org.eclipse.egit.ui.internal.repository.NewRemoteWizard.java
License:Open Source License
@Override public boolean performFinish() { RemoteConfig config; try {/*from w ww. jav a 2 s .co m*/ config = new RemoteConfig(myConfiguration, selNamePage.remoteName.getText()); } catch (URISyntaxException e1) { // TODO better Exception handling return false; } if (selNamePage.configureFetch.getSelection()) { config.addURI(configureFetchUriPage.getUri()); config.setFetchRefSpecs(configureFetchSpecPage.getRefSpecs()); config.setTagOpt(configureFetchSpecPage.getTagOpt()); } if (selNamePage.configurePush.getSelection()) { for (URIish uri : configurePushUriPage.getUris()) config.addPushURI(uri); config.setPushRefSpecs(configurePushSpecPage.getRefSpecs()); } config.update(myConfiguration); try { myConfiguration.save(); return true; } catch (IOException e) { // TODO better Exception handling return false; } }