RemoteConfig remote = new RemoteConfig(config, name); if (push) { List<URIish> uris = remote.getPushURIs(); if (uris.size() > 1) { throw new JGitInternalException( "remote.newtest.pushurl has multiple values"); //$NON-NLS-1$ } else if (uris.size() == 1) { remote.removePushURI(uris.get(0)); remote.addPushURI(uri); } else { List<URIish> uris = remote.getURIs(); if (uris.size() > 1) { throw new JGitInternalException( "remote.newtest.url has multiple values"); //$NON-NLS-1$ } else if (uris.size() == 1) { remote.removeURI(uris.get(0)); remote.addURI(uri); remote.update(config); config.save(); return remote;
/** * Update this remote's definition within the configuration. * * @param rc * the configuration file to store ourselves into. */ public void update(Config rc) { final List<String> vlst = new ArrayList<>(); vlst.clear(); for (URIish u : getURIs()) vlst.add(u.toPrivateString()); rc.setStringList(SECTION, getName(), KEY_URL, vlst); vlst.clear(); for (URIish u : getPushURIs()) vlst.add(u.toPrivateString()); rc.setStringList(SECTION, getName(), KEY_PUSHURL, vlst); vlst.clear(); for (RefSpec u : getFetchRefSpecs()) vlst.add(u.toString()); rc.setStringList(SECTION, getName(), KEY_FETCH, vlst); vlst.clear(); for (RefSpec u : getPushRefSpecs()) vlst.add(u.toString()); rc.setStringList(SECTION, getName(), KEY_PUSH, vlst); set(rc, KEY_UPLOADPACK, getUploadPack(), DEFAULT_UPLOAD_PACK); set(rc, KEY_RECEIVEPACK, getReceivePack(), DEFAULT_RECEIVE_PACK); set(rc, KEY_TAGOPT, getTagOpt().option(), TagOpt.AUTO_FOLLOW.option()); set(rc, KEY_MIRROR, mirror, DEFAULT_MIRROR); set(rc, KEY_TIMEOUT, timeout, 0); }
/** * {@inheritDoc} * <p> * Executes the {@code remote add} command with all the options and * parameters collected by the setter methods of this class. */ @Override public RemoteConfig call() throws GitAPIException { checkCallable(); try { StoredConfig config = repo.getConfig(); RemoteConfig remote = new RemoteConfig(config, name); RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$ Constants.R_REMOTES + name + "/*"); //$NON-NLS-1$ remote.addFetchRefSpec(refSpec); remote.addURI(uri); remote.update(config); config.save(); return remote; } catch (IOException | URISyntaxException e) { throw new JGitInternalException(e.getMessage(), e); } }
public static ArrayMemory valueOf(RemoteConfig value) { ArrayMemory memory = new ArrayMemory(); memory.refOfIndex("name").assign(value.getName()); memory.refOfIndex("receivePack").assign(value.getReceivePack()); memory.refOfIndex("uploadPack").assign(value.getUploadPack()); memory.refOfIndex("mirror").assign(value.isMirror()); memory.refOfIndex("timeout").assign(value.getTimeout()); memory.refOfIndex("tagOpt").assign(value.getTagOpt().name()); ArrayMemory uris = ArrayMemory.createListed(value.getURIs().size()); for (URIish urIish : value.getURIs()) { uris.add(urIish.toPrivateString()); } memory.refOfIndex("uris").assign(uris); return memory; }
private static boolean doesNotExist(RemoteConfig cfg) { return cfg.getURIs().isEmpty() && cfg.getPushURIs().isEmpty(); }
private void addOrigin() throws URISyntaxException, GitAPIException { RemoteAddCommand add = git.remoteAdd(); add.setName("origin"); String uri = "https://example.org/repo"; add.setUri(new URIish(uri)); add.call(); assertEquals("origin", git.remoteList().call().iterator().next().getName()); assertEquals(uri, git.remoteList().call().iterator().next().getURIs().iterator().next().toString()); } }
private FetchResult fetch(Repository clonedRepo, URIish u) throws URISyntaxException, org.eclipse.jgit.api.errors.TransportException, IOException, GitAPIException { // create the remote config and save it RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote); config.addURI(u); final String dst = (bare ? Constants.R_HEADS : Constants.R_REMOTES + config.getName() + '/') + '*'; boolean fetchAll = cloneAllBranches || branchesToClone == null || branchesToClone.isEmpty(); config.setFetchRefSpecs(calculateRefSpecs(fetchAll, dst)); config.update(clonedRepo.getConfig()); clonedRepo.getConfig().save(); // run the fetch command FetchCommand command = new FetchCommand(clonedRepo); command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(fetchAll ? TagOpt.FETCH_TAGS : TagOpt.AUTO_FOLLOW); configure(command); return command.call(); }
private URL getUrlFromFirstConfiguredRepository(GitChangeSet changeSet) throws MalformedURLException { GitSCM scm = getScmFromProject(changeSet); return new URL(scm.getRepositories().get(0).getURIs().get(0).toString()); }
@Override public void widgetSelected(SelectionEvent e) { SelectUriWizard wiz; if (commonUriText.getText().length() > 0) wiz = new SelectUriWizard(true, commonUriText.getText()); else wiz = new SelectUriWizard(true); if (new WizardDialog(getShell(), wiz).open() == Window.OK) { if (commonUriText.getText().length() > 0) try { config.removeURI(new URIish(commonUriText.getText())); } catch (URISyntaxException ex) { Activator.handleError(ex.getMessage(), ex, true); } config.addURI(wiz.getUri()); updateControls(); } } });
throws NotSupportedException, URISyntaxException, TransportException { final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); if (doesNotExist(cfg)) { final ArrayList<Transport> transports = new ArrayList<>(1); transports.add(open(local, new URIish(remote), null)); return transports;
for (RemoteConfig rc : RemoteConfig.getAllRemoteConfigs(repository .getConfig())) { if (rc.getURIs().size() > 0) uris.add(rc.getURIs().get(0).toPrivateString()); for (URIish u : rc.getPushURIs()) uris.add(u.toPrivateString());
private String retrieveRevisionToBuild(PushHook hook, GitSCM gitSCM) throws NoRevisionToBuildException { if (inNoBranchDelete(hook)) { if (gitSCM != null && gitSCM.getRepositories().size() == 1) { String repositoryName = gitSCM.getRepositories().get(0).getName(); return hook.getRef().replaceFirst("^refs/heads", "remotes/" + repositoryName); } else { return hook.getAfter(); } } else { throw new NoRevisionToBuildException(); } }
RemoteConfig rc = new RemoteConfig(cfg, name); List<URIish> uris = rc.getPushURIs(); if (uris.isEmpty()) { uris = rc.getURIs(); String n = uris.size() == 1 ? name : uri.getHost(); replicas.add(new RemoteGitReplica(leader, n, uri, kc, rc));
@Override public String getKey() { String name = getScmName(); if (name != null) { return name; } StringBuilder b = new StringBuilder("git"); for (RemoteConfig cfg : getRepositories()) { for (URIish uri : cfg.getURIs()) { b.append(' ').append(uri.toString()); } } return b.toString(); }
/** * Expand parameters in {@link #remoteRepositories} with the parameter values provided in the given build * and return them. * * @return can be empty but never null. */ public List<RemoteConfig> getParamExpandedRepos(AbstractBuild<?, ?> build) { List<RemoteConfig> expandedRepos = new ArrayList<RemoteConfig>(); for (RemoteConfig oldRepo : Util.fixNull(remoteRepositories)) { expandedRepos.add(newRemoteConfig(oldRepo.getName(), oldRepo.getURIs().get(0).toPrivateString(), new RefSpec(getRefSpec(oldRepo, build)), getRemoteConfigTargetDir(oldRepo))); } return expandedRepos; }
public void fetch(RemoteConfig remoteRepository) throws GitException { // Assume there is only 1 URL / refspec for simplicity fetch(remoteRepository.getURIs().get(0).toPrivateString(), remoteRepository.getFetchRefSpecs().get(0).toString()); }
/** * Expand Parameters in the supplied remote repository with the parameter values provided in the given environment variables } * @param env Environment variables with parameter values * @param remoteRepository Remote repository with parameters * @return remote repository with expanded parameters */ public RemoteConfig getParamExpandedRepo(EnvVars env, RemoteConfig remoteRepository){ List<RefSpec> refSpecs = getRefSpecs(remoteRepository, env); return newRemoteConfig( getParameterString(remoteRepository.getName(), env), getParameterString(remoteRepository.getURIs().get(0).toPrivateString(), env), refSpecs.toArray(new RefSpec[refSpecs.size()])); }
private void addRemoteRepoToConfig(GitClient client) throws InterruptedException { GitSCM gitScm = getJenkinsScm(); for (RemoteConfig uc : gitScm.getRepositories()) { if (client.getRemoteUrl(uc.getName()) == null) client.setRemoteUrl(uc.getName(), uc.getURIs().get(0).toPrivateASCIIString()); } }
/** * Apply provided remote configuration on this transport. * * @param cfg * configuration to apply on this transport. */ public void applyConfig(RemoteConfig cfg) { setOptionUploadPack(cfg.getUploadPack()); setOptionReceivePack(cfg.getReceivePack()); setTagOpt(cfg.getTagOpt()); fetch = cfg.getFetchRefSpecs(); push = cfg.getPushRefSpecs(); timeout = cfg.getTimeout(); }