remote.removeURI(uris.get(0)); remote.addURI(uri);
/** * {@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); } }
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(); }
// setup the first repository to fetch from the second repository final StoredConfig config = db.getConfig(); RemoteConfig remoteConfig = new RemoteConfig(config, "test"); URIish uri = new URIish(db2.getDirectory().toURI().toURL()); remoteConfig.addURI(uri); remoteConfig.update(config); config.save(); // create some refs via commits and tag RevCommit commit = git2.commit().setMessage("initial commit").call(); Ref tagRef = git2.tag().setName("tag").call(); Git git1 = new Git(db); RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x"); git1.fetch().setRemote("test").setRefSpecs(spec) .call();
@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(); } } });
@Override public void widgetSelected(SelectionEvent e) { SelectUriWizard wiz; if (commonUriText.getText().length() > 0) wiz = new SelectUriWizard(false, commonUriText.getText()); else wiz = new SelectUriWizard(false); 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(); } } });
@Nonnull private RemoteConfig getRemoteConfig(final URIish uri, final StoredConfig config) throws URISyntaxException, IOException { RemoteConfig remote = new RemoteConfig(config, "origin"); remote.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination("refs/heads/*", "refs/remotes/origin/*")); remote.addURI(uri); remote.update(config); config.save(); return remote; }
remoteConfig.addURI(gitUri);
remote.removeURI(uris.get(0)); remote.addURI(uri);
remote.removeURI(uris.get(0)); remote.addURI(uri);
public List<RefSpec> execute() throws IOException, URISyntaxException { final List<RefSpec> specs = new ArrayList<>(); if (refSpecs == null || refSpecs.isEmpty()) { specs.add(new RefSpec("+refs/heads/*:refs/remotes/" + remote.getK1() + "/*")); specs.add(new RefSpec("+refs/tags/*:refs/tags/*")); specs.add(new RefSpec("+refs/notes/*:refs/notes/*")); } else { specs.addAll(refSpecs); } final StoredConfig config = git.getRepository().getConfig(); final String url = config.getString("remote", remote.getK1(), "url"); if (url == null) { final RemoteConfig remoteConfig = new RemoteConfig(git.getRepository().getConfig(), remote.getK1()); remoteConfig.addURI(new URIish(remote.getK2())); specs.forEach(remoteConfig::addFetchRefSpec); remoteConfig.update(git.getRepository().getConfig()); git.getRepository().getConfig().save(); } return specs; } }
private void saveRemote(final URIish uri) throws URISyntaxException, IOException { final StoredConfig dstcfg = dst.getConfig(); final RemoteConfig rc = new RemoteConfig(dstcfg, remoteName); rc.addURI(uri); rc.addFetchRefSpec(new RefSpec().setForceUpdate(true) .setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$ Constants.R_REMOTES + remoteName + "/*")); //$NON-NLS-1$ rc.update(dstcfg); dstcfg.save(); }
/** * Executes the {@code remote add} command with all the options and * parameters collected by the setter methods of this class. * * @return the {@link RemoteConfig} object of the added remote */ @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); } }
/** * {@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); } }
/** * Set a remote repository path. * * @param repositoryDirectory The directory in which the git repo exists. * @param remoteName The name of the remote (i.e. 'origin') * @param remoteUrl The url of the repository. */ public static void setRemote(Path repositoryDirectory, String remoteName, String remoteUrl) { Git git = null; try { git = Git.open(repositoryDirectory.toFile()); StoredConfig config = git.getRepository().getConfig(); config.unsetSection("remote", remoteName); RemoteConfig remoteConfig = new RemoteConfig(config, remoteName); remoteConfig.addURI(new URIish(remoteUrl)); remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remoteName + "/*")); remoteConfig.update(config); config.save(); } catch (URISyntaxException | IOException e) { throw new GitException("Unable to set the remote repository", e); } finally { close(git); } }
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 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() + "/") + "*"; //$NON-NLS-1$//$NON-NLS-2$ RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", dst); //$NON-NLS-1$ config.addFetchRefSpec(refSpec); config.update(clonedRepo.getConfig()); clonedRepo.getConfig().save(); // run the fetch command FetchCommand command = new FetchCommand(clonedRepo); command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(TagOpt.FETCH_TAGS); configure(command); List<RefSpec> specs = calculateRefSpecs(dst); command.setRefSpecs(specs); return command.call(); }
remoteName); rc.addURI(uri);