checkCallable(); try (Transport transport = Transport.open(repo, remote)) { transport.setCheckFetchedObjects(checkFetchedObjects); transport.setRemoveDeletedRefs(isRemoveDeletedRefs()); transport.setDryRun(dryRun); if (tagOption != null) transport.setTagOpt(tagOption); transport.setFetchThin(thin); configure(transport); FetchResult result = transport.fetch(monitor, applyOptions(refSpecs)); if (!repo.isBare()) {
transports = Transport.openAll(repo, remote, Transport.Operation.PUSH); for (@SuppressWarnings("resource") // Explicitly closed in finally final Transport transport : transports) { transport.setPushThin(thin); transport.setPushAtomic(atomic); if (receivePack != null) transport.setOptionReceivePack(receivePack); transport.setDryRun(dryRun); transport.setPushOptions(pushOptions); configure(transport); .findRemoteRefUpdatesFor(refSpecs, refLeaseSpecs); PushResult result = transport.push(monitor, toPush, out); pushResults.add(result); e.getMessage(), e); } finally { transport.close();
/** * Configure transport with credentials provider, timeout, and config * callback * * @param transport * a {@link org.eclipse.jgit.transport.Transport} object. * @return {@code this} */ protected C configure(Transport transport) { if (credentialsProvider != null) transport.setCredentialsProvider(credentialsProvider); transport.setTimeout(timeout); if (transportConfigCallback != null) transportConfigCallback.configure(transport); return self(); }
Memory timeout = settings.valueOfIndex("timeout"); if (timeout != null) { transport.setTimeout(timeout.toInteger()); transport.setDryRun(settings.valueOfIndex("dryRun").toBoolean()); transport.setCheckFetchedObjects(settings.valueOfIndex("checkFetchedObjects").toBoolean()); transport.setFetchThin(settings.valueOfIndex("fetchThin").toBoolean()); transport.setPushAtomic(settings.valueOfIndex("pushAtomic").toBoolean()); transport.setPushThin(settings.valueOfIndex("pushThin").toBoolean()); transport.setRemoveDeletedRefs(settings.valueOfIndex("removeDeletedRefs").toBoolean());
/** {@inheritDoc} */ @Override protected void blockingFetch(Repository repo, ReplicaFetchRequest req) throws NotSupportedException, TransportException { try (Transport transport = Transport.open(repo, uri)) { RemoteConfig rc = getRemoteConfig(); if (rc != null) { transport.applyConfig(rc); } fetch(transport, req); } }
private Set<String> listRemoteBranches(String remote) throws NotSupportedException, TransportException, URISyntaxException { Set<String> branches = new HashSet<>(); try (final Repository repo = getRepository()) { StoredConfig config = repo.getConfig(); try (final Transport tn = Transport.open(repo, new URIish(config.getString("remote",remote,"url")))) { tn.setCredentialsProvider(getProvider()); try (final FetchConnection c = tn.openFetch()) { for (final Ref r : c.getRefs()) { if (r.getName().startsWith(R_HEADS)) branches.add("refs/remotes/"+remote+"/"+r.getName().substring(R_HEADS.length())); } } } } return branches; }
/** * Open new transport instances to connect two repositories. * * @param local * existing local repository. * @param cfg * configuration describing how to connect to the remote * repository. * @param op * planned use of the returned Transport; the URI may differ * based on the type of connection desired. * @return the list of new transport instances for every URI in remote * configuration. * @throws org.eclipse.jgit.errors.NotSupportedException * the protocol specified is not supported. * @throws org.eclipse.jgit.errors.TransportException * the transport cannot open this URI. */ public static List<Transport> openAll(final Repository local, final RemoteConfig cfg, final Operation op) throws NotSupportedException, TransportException { final List<URIish> uris = getURIs(cfg, op); final List<Transport> transports = new ArrayList<>(uris.size()); for (URIish uri : uris) { final Transport tn = open(local, uri, cfg.getName()); tn.applyConfig(cfg); transports.add(tn); } return transports; }
public static void push(Repository repo, String remoteName, List<RemoteRefUpdate> refsToUpdate, String remoteUserName, String remotePassword) throws IOException, URISyntaxException { ArrayList<PushResult> pushResults = new ArrayList<PushResult>(3); RemoteConfig config = new RemoteConfig(repo.getConfig(), remoteName); final List<Transport> transports; transports = Transport.openAll(repo, config, Transport.Operation.PUSH); for (final Transport transport : transports) { transport.setPushThin(false); transport.setOptionReceivePack(RemoteConfig.DEFAULT_RECEIVE_PACK); transport.setDryRun(false); configure(transport, remoteUserName, remotePassword); try { PushResult result = transport.push(new TextProgressMonitor(), refsToUpdate, System.out); pushResults.add(result); } catch (TransportException e) { throw new TransportException(e.getMessage(), e); } finally { transport.close(); } } }
Transport tn = Transport.open(repository, "origin"); tn.setCredentialsProvider(credentialsProvider); r = tn.fetch(new TextProgressMonitor(), refSpecs); tn.close();
callCommand(cmd); List<Transport> transports = Transport.openAll(repository, "origin", Transport.Operation.PUSH); transport.setCredentialsProvider(credentialsProvider); transport.findRemoteRefUpdatesFor(refSpecs); PushResult result = transport.push(new TextProgressMonitor(), toPush); Collection<RemoteRefUpdate> refUpdates = result.getRemoteUpdates(); transport.close();
private void executeImp(final ProgressMonitor monitor, final FetchResult result) throws NotSupportedException, TransportException { conn = transport.openFetch(); try { result.setAdvertisedRefs(transport.getURI(), conn.getRefsMap()); result.peerUserAgent = conn.getPeerUserAgent(); final Set<Ref> matched = new HashSet<>(); final TagOpt tagopt = transport.getTagOpt(); if (tagopt == TagOpt.AUTO_FOLLOW) additionalTags = expandAutoFollowTags(); 250, TimeUnit.MILLISECONDS); if (transport.isRemoveDeletedRefs()) { deleteStaleTrackingRefs(result, batch); cmd.setResult(REJECTED_NONFASTFORWARD); if (transport.isDryRun()) { for (ReceiveCommand cmd : batch.getCommands()) { if (cmd.getResult() == NOT_ATTEMPTED)
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; return openAll(local, cfg, op);
? Transport.open(repo, remote) : Transport.open(new URIish(remote))) { transport.setOptionUploadPack(uploadPack); configure(transport); Collection<RefSpec> refSpecs = new ArrayList<>(1); Collection<Ref> refs; Map<String, Ref> refmap = new HashMap<>(); try (FetchConnection fc = transport.openFetch()) { refs = fc.getRefs(); if (refSpecs.isEmpty())
@Override protected void run() throws Exception { final Transport tn = Transport.open(db, remote); if (0 <= timeout) tn.setTimeout(timeout); final FetchConnection c = tn.openFetch(); try { for (final Ref r : c.getRefs()) { show(r.getObjectId(), r.getName()); if (r.getPeeledObjectId() != null) show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ } } finally { c.close(); tn.close(); } }
private void push(Repository repo, ReplicaPushRequest req) throws NotSupportedException, TransportException, IOException { Map<String, Ref> adv; List<RemoteCommand> cmds = asUpdateList(req.getCommands()); try (Transport transport = Transport.open(repo, uri)) { RemoteConfig rc = getRemoteConfig(); if (rc != null) { transport.applyConfig(rc); } transport.setPushAtomic(true); adv = push(repo, transport, cmds); } for (RemoteCommand c : cmds) { c.copyStatusToResult(); } req.setRefs(adv); }
/** * Open a new transport instance to connect two repositories. * * @param local * existing local repository. * @param uri * location of the remote repository. * @return the new transport instance. Never null. * @throws org.eclipse.jgit.errors.NotSupportedException * the protocol specified is not supported. * @throws org.eclipse.jgit.errors.TransportException * the transport cannot open this URI. */ public static Transport open(Repository local, URIish uri) throws NotSupportedException, TransportException { return open(local, uri, null); }
protected FetchResult doRemoteUpdate() throws IOException { List<RemoteConfig> remoteConfig = null; try { LOGGER.debug("Fetching remote configurations from repository configuration"); remoteConfig = RemoteConfig.getAllRemoteConfigs(repository.getConfig()); } catch (URISyntaxException e) { throw new ScmException(e); } LOGGER.debug("Opening transport to {}", remoteConfig.get(0).getName()); Transport transport = Transport.open(repository, remoteConfig.get(0)); try { LOGGER.debug("Fetching content from remote repository"); return transport.fetch(NullProgressMonitor.INSTANCE, null); } finally { if (transport != null) { transport.close(); } } }
if (local != null) { final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); if (doesNotExist(cfg)) return open(local, new URIish(remote), null); return open(local, cfg, op); } else return open(new URIish(remote));
/** * Convert push remote refs update specification from * {@link org.eclipse.jgit.transport.RefSpec} form to * {@link org.eclipse.jgit.transport.RemoteRefUpdate}. Conversion expands * wildcards by matching source part to local refs. expectedOldObjectId in * RemoteRefUpdate is set according to leases. Tracking branch is configured * if RefSpec destination matches source of any fetch ref spec for this * transport remote configuration. * <p> * Conversion is performed for context of this transport (database, fetch * specifications). * * @param specs * collection of RefSpec to convert. * @param leases * map from ref to lease (containing expected old object id) * @return collection of set up * {@link org.eclipse.jgit.transport.RemoteRefUpdate}. * @throws java.io.IOException * when problem occurred during conversion or specification set * up: most probably, missing objects or refs. * @since 4.7 */ public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor( final Collection<RefSpec> specs, final Map<String, RefLeaseSpec> leases) throws IOException { return findRemoteRefUpdatesFor(local, specs, leases, fetch); }