private List<RefSpec> calculateRefSpecs(boolean fetchAll, String dst) { RefSpec wcrs = new RefSpec(); wcrs = wcrs.setForceUpdate(true); wcrs = wcrs.setSourceDestination(Constants.R_HEADS + '*', dst); List<RefSpec> specs = new ArrayList<>(); if (!fetchAll) { for (String selectedRef : branchesToClone) { if (wcrs.matchSource(selectedRef)) { specs.add(wcrs.expandFromSource(selectedRef)); } } } else { specs.add(wcrs); } return specs; }
/** * {@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 List<RefSpec> calculateRefSpecs(final String dst) { RefSpec wcrs = new RefSpec(); wcrs = wcrs.setForceUpdate(true); wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst); //$NON-NLS-1$ List<RefSpec> specs = new ArrayList<RefSpec>(); if (cloneAllBranches) specs.add(wcrs); else if (branchesToClone != null && branchesToClone.size() > 0) { for (final String selectedRef : branchesToClone) if (wcrs.matchSource(selectedRef)) specs.add(wcrs.expandFromSource(selectedRef)); } return specs; }
private List<RefSpec> calculateRefSpecs(boolean fetchAll, String dst) { RefSpec wcrs = new RefSpec(); wcrs = wcrs.setForceUpdate(true); wcrs = wcrs.setSourceDestination(Constants.R_HEADS + '*', dst); List<RefSpec> specs = new ArrayList<>(); if (!fetchAll) { for (String selectedRef : branchesToClone) { if (wcrs.matchSource(selectedRef)) { specs.add(wcrs.expandFromSource(selectedRef)); } } } else { specs.add(wcrs); } return specs; }
@Override public String fetch(String localBranchName, String remoteBranchName) { RefSpec spec = new RefSpec().setSourceDestination(localBranchName, remoteBranchName); FetchCommand command = _git.fetch(); command.setRefSpecs(spec); FetchResult result = null; try { if(_cp != null) command.setCredentialsProvider(_cp); result = command.call(); } catch (Throwable e) { throw new RuntimeException(String.format( "Failed to fetch from [%s] to [%s]", remoteBranchName, localBranchName), e); } return result.getMessages(); }
@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; }
private static RefSpec setRefSpecDestination(final RefSpec spec, final String dst) { final String src; if (RefSpec.isWildcard(dst)) src = wildcardSpecComponent(spec.getSource()); else src = unwildcardSpecComponent(spec.getSource(), dst); return spec.setSourceDestination(src, dst); }
private static RefSpec setRefSpecSource(final RefSpec spec, final String src) { final String dst; if (RefSpec.isWildcard(src)) dst = wildcardSpecComponent(spec.getDestination()); else dst = unwildcardSpecComponent(spec.getDestination(), src); return spec.setSourceDestination(src, dst); }
RefSpec refSpec = new RefSpec().setSourceDestination(sourceBranch, destinationBranch); command.setRefSpecs(refSpec); try {
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); } }
@Override public boolean performFinish() { try { 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; }
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(); }
wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst + "/*");