List of usage examples for org.eclipse.jgit.transport RemoteConfig addPushURI
public boolean addPushURI(URIish toAdd)
From source file:org.commonjava.gitwrap.BareGitRepository.java
License:Open Source License
public BareGitRepository setPushTarget(final String name, final String uri, final boolean heads, final boolean tags) throws GitWrapException { try {//from w ww. j a va 2s.c o m final RemoteConfig remote = new RemoteConfig(repository.getConfig(), name); final URIish uriish = new URIish(uri); final List<URIish> uris = remote.getURIs(); if (uris == null || !uris.contains(uriish)) { remote.addURI(uriish); } final List<URIish> pushURIs = remote.getPushURIs(); if (pushURIs == null || !pushURIs.contains(uriish)) { remote.addPushURI(uriish); } final List<RefSpec> pushRefSpecs = remote.getPushRefSpecs(); if (heads) { final RefSpec headSpec = new RefSpec("+" + Constants.R_HEADS + "*:" + Constants.R_HEADS + "*"); if (pushRefSpecs == null || !pushRefSpecs.contains(headSpec)) { remote.addPushRefSpec(headSpec); } } if (tags) { final RefSpec tagSpec = new RefSpec("+" + Constants.R_TAGS + "*:" + Constants.R_TAGS + "*"); if (pushRefSpecs == null || !pushRefSpecs.contains(tagSpec)) { remote.addPushRefSpec(tagSpec); } } remote.update(repository.getConfig()); repository.getConfig().save(); } catch (final URISyntaxException e) { throw new GitWrapException("Invalid URI-ish: %s. Nested error: %s", e, uri, e.getMessage()); } catch (final IOException e) { throw new GitWrapException("Failed to write Git config: %s", e, e.getMessage()); } return this; }
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); }/*from ww w . j a v a 2 s .c om*/ 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.core.internal.gerrit.GerritUtil.java
License:Open Source License
/** * Configure the pushURI for Gerrit/*from w w w. j a v a 2 s .co m*/ * * @param remoteConfig * the remote configuration to add this to * @param pushURI * the pushURI to configure */ public static void configurePushURI(RemoteConfig remoteConfig, URIish pushURI) { List<URIish> pushURIs = new ArrayList<URIish>(remoteConfig.getPushURIs()); for (URIish urIish : pushURIs) { remoteConfig.removePushURI(urIish); } remoteConfig.addPushURI(pushURI); }
From source file:org.eclipse.egit.core.op.ConfigurePushAfterCloneTask.java
License:Open Source License
/** * @param repository//from w w w . j a v a2 s. c o m * @param monitor * @throws CoreException */ public void execute(Repository repository, IProgressMonitor monitor) throws CoreException { try { RemoteConfig configToUse = new RemoteConfig(repository.getConfig(), remoteName); if (pushRefSpec != null) configToUse.addPushRefSpec(new RefSpec(pushRefSpec)); if (pushURI != null) configToUse.addPushURI(pushURI); configToUse.update(repository.getConfig()); repository.getConfig().save(); } catch (Exception e) { throw new CoreException(Activator.error(e.getMessage(), e)); } }
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. ja va2 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; } }
From source file:org.eclipse.oomph.setup.git.impl.GitCloneTaskImpl.java
License:Open Source License
private static boolean addPushURI(SetupTaskContext context, StoredConfig config, String remoteName, String pushURI) throws Exception { boolean uriAdded = false; if (!StringUtil.isEmpty(pushURI)) { URIish uri = new URIish(pushURI); for (RemoteConfig remoteConfig : RemoteConfig.getAllRemoteConfigs(config)) { if (remoteName.equals(remoteConfig.getName())) { if (context.isPerforming()) { context.log("Adding push URI: " + pushURI); }//from www . j a v a 2 s. c om uriAdded = remoteConfig.addPushURI(uri); if (uriAdded) { remoteConfig.update(config); } break; } } } return uriAdded; }
From source file:org.eclipse.orion.server.git.servlets.GitRemoteHandlerV1.java
License:Open Source License
private boolean addRemote(HttpServletRequest request, HttpServletResponse response, String path) throws IOException, JSONException, ServletException, CoreException, URISyntaxException { // expected path: /git/remote/file/{path} Path p = new Path(path); JSONObject toPut = OrionServlet.readJSONRequest(request); String remoteName = toPut.optString(GitConstants.KEY_REMOTE_NAME, null); // remoteName is required if (remoteName == null || remoteName.isEmpty()) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Remote name must be provided", null)); }/*from w w w . j ava2 s. c o m*/ String remoteURI = toPut.optString(GitConstants.KEY_REMOTE_URI, null); // remoteURI is required if (remoteURI == null || remoteURI.isEmpty()) { return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Remote URI must be provided", null)); } String fetchRefSpec = toPut.optString(GitConstants.KEY_REMOTE_FETCH_REF, null); String remotePushURI = toPut.optString(GitConstants.KEY_REMOTE_PUSH_URI, null); String pushRefSpec = toPut.optString(GitConstants.KEY_REMOTE_PUSH_REF, null); File gitDir = GitUtils.getGitDir(p); Repository db = new FileRepository(gitDir); StoredConfig config = db.getConfig(); RemoteConfig rc = new RemoteConfig(config, remoteName); rc.addURI(new URIish(remoteURI)); // FetchRefSpec is required, but default version can be generated // if it isn't provided if (fetchRefSpec == null || fetchRefSpec.isEmpty()) { fetchRefSpec = String.format("+refs/heads/*:refs/remotes/%s/*", remoteName); //$NON-NLS-1$ } rc.addFetchRefSpec(new RefSpec(fetchRefSpec)); // pushURI is optional if (remotePushURI != null && !remotePushURI.isEmpty()) rc.addPushURI(new URIish(remotePushURI)); // PushRefSpec is optional if (pushRefSpec != null && !pushRefSpec.isEmpty()) rc.addPushRefSpec(new RefSpec(pushRefSpec)); rc.update(config); config.save(); URI baseLocation = getURI(request); JSONObject result = toJSON(remoteName, baseLocation); OrionServlet.writeJSONResponse(request, response, result); response.setHeader(ProtocolConstants.HEADER_LOCATION, result.getString(ProtocolConstants.KEY_LOCATION)); response.setStatus(HttpServletResponse.SC_CREATED); return true; }