@Override public String apply(Remote remote) { return remote.getName(); } };
public static RemoteInfo create(Remote remote) { RemoteInfo ri = new RemoteInfo(); String name = remote.getName(); ri.setName(name); String url = remote.getFetchURL(); ri.setURL(url); String userName = remote.getUserName(); ri.setUserName(userName); String password = remote.getPassword(); if (password != null) { password = Remote.decryptPassword(password); } ri.setPassword(password); ri.id = ri.hashCode(); return ri; }
/** * Executes the remote list command. */ @Override public void runInternal(GeogigCLI cli) throws IOException { final ImmutableList<Remote> remoteList; try { remoteList = cli.getGeogig().command(RemoteListOp.class).call(); } catch (ConfigException e) { throw new CommandFailedException("Could not access the config database.", e); } for (Remote remote : remoteList) { if (verbose) { cli.getConsole() .println(remote.getName() + " " + remote.getFetchURL() + " (fetch)"); cli.getConsole().println(remote.getName() + " " + remote.getPushURL() + " (push)"); } else { cli.getConsole().println(remote.getName()); } } }
String fetchURL = remote.getFetchURL(); URI fetchURI = URI.create(fetchURL); final String protocol = fetchURI.getScheme(); final String username = remote.getUserName(); final String password = remote.getPassword(); if (username != null && password != null) { Authenticator.setDefault(new Authenticator() { Authenticator.setDefault(null); if (remote.getMapped()) { remoteRepo = new HttpMappedRemoteRepo(remote, fetchURI.toURL()); } else {
public @Override Optional<IRemoteRepo> resolve(Remote remote, Hints remoteHints) { final String fetchURL = remote.getFetchURL(); final URI fetchURI = URI.create(fetchURL); final String scheme = fetchURI.getScheme(); Preconditions.checkNotNull(scheme, "Fetch URI doesn't declare scheme: %s", fetchURL); if (RepositoryResolver.resolverAvailableForURIScheme(scheme)) { IRemoteRepo remoteRepo = null; if (remote.getMapped()) { remoteRepo = new LocalMappedRemoteRepo(remote, fetchURI); } else { remoteRepo = new LocalRemoteRepo(remote, fetchURI); } return Optional.of(remoteRepo); } return Optional.absent(); } }
@Test public void testAddRemoteNullBranch() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).setBranch(null).call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); }
@Test public void testAddRemoteNullBranch() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).setBranch(null).call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", remote.getFetch()); }
@Test public void testConstructorAndAccessors() { Remote remote = new Remote("name", "fetchurl", "pushurl", "fetch", true, "mappedBranch", "username", "password"); assertEquals("name", remote.getName()); assertEquals("fetchurl", remote.getFetchURL()); assertEquals("pushurl", remote.getPushURL()); assertEquals("fetch", remote.getFetchSpec()); assertEquals(true, remote.getMapped()); assertEquals("mappedBranch", remote.getMappedBranch()); assertEquals("username", remote.getUserName()); assertEquals("password", remote.getPassword()); Remote remote2 = new Remote("name", "fetchurl", "pushurl", "fetch", false, null, null, null); assertEquals("name", remote2.getName()); assertEquals("fetchurl", remote2.getFetchURL()); assertEquals("pushurl", remote2.getPushURL()); assertEquals("fetch", remote2.getFetchSpec()); assertEquals(false, remote2.getMapped()); assertEquals("*", remote2.getMappedBranch()); assertEquals(null, remote2.getUserName()); assertEquals(null, remote2.getPassword()); new Remote("name", "validuri", "fi:\\invalidURI", "fetch", false, null, null, null); fail(); } catch (IllegalArgumentException e) { new Remote("name", "fi:\\invalidURI", "validuri", "fetch", false, null, null, null); fail();
private boolean isHttp(FetchArgs args) { for (Remote r : args.remotes) { if (r.getFetchURL().startsWith("http")) { return true; } } return false; }
/** * Writes the response for the {@link RemoteManagement} command to the stream. * * @param remotes the list of the {@link Remote}s of this repository * @throws StreamWriterException */ public void writeRemoteListResponse(List<Remote> remotes, boolean verbose) throws StreamWriterException { out.writeStartArray("Remote"); for (Remote remote : remotes) { out.writeStartArrayElement("Remote"); writeElement("name", remote.getName()); if (verbose) { writeElement("url", remote.getFetchURL()); if (remote.getUserName() != null) { writeElement("username", remote.getUserName()); } } out.writeEndArrayElement(); } out.writeEndArray(); }
private void testDeleteRemoteRef(String refSpec) throws Exception { Preconditions.checkArgument(refSpec.startsWith(":") && refSpec.length() > 1); String refName = refSpec.substring(1); Optional<Ref> ref = getRef(remoteRepo, refName); assertTrue(ref.isPresent()); PushOp push = pushOp(); push.addRefSpec(refSpec); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), ref, absent()); assertFalse(remoteRepo.command(RefParse.class).setName(refName).call().isPresent()); }
String fetchSpec = remote.getFetchSpec(); fetchSpec += ";+refs/tags/*:refs/tags/*"; remote = remote.fetch(fetchSpec); Preconditions.checkState(remote.equals(remoteRepo.getInfo())); progress.setDescription("Fetching " + remoteRepo.getInfo()); final List<LocalRemoteRef> localToRemoteRemoteRefs = resolveRemoteRefs(remoteRepo); transferSummary.addAll(remote.getFetchURL(), Lists.newArrayList(remoteRemoteRefs)); progress.setDescription("Fetched " + remoteRepo.getInfo());
public Remote toRemote() { String fetchurl = this.URL; String pushurl = this.URL; String fetch = "+" + Ref.HEADS_PREFIX + "*:" + Ref.REMOTES_PREFIX + name + "/*"; boolean mapped = false; String mappedBranch = null; Remote r = new Remote( name, fetchurl, pushurl, fetch, mapped, mappedBranch, userName, password); return r; }
private Ref updateLocalRef(Ref remoteRef, Remote remote, ImmutableSet<Ref> localRemoteRefs) { final String refName; if (remoteRef.getName().startsWith(Ref.TAGS_PREFIX)) { refName = remoteRef.getName(); } else { refName = Ref.REMOTES_PREFIX + remote.getName() + "/" + remoteRef.localName(); } Ref updatedRef = remoteRef; if (remoteRef instanceof SymRef) { String targetBranch = Ref.localName(((SymRef) remoteRef).getTarget()); String newTarget = Ref.REMOTES_PREFIX + remote.getName() + "/" + targetBranch; updatedRef = command(UpdateSymRef.class).setName(refName).setNewValue(newTarget).call() .get(); } else { ObjectId effectiveId = remoteRef.getObjectId(); if (remote.getMapped() && !repository().commitExists(remoteRef.getObjectId())) { effectiveId = graphDatabase().getMapping(effectiveId); } updatedRef = command(UpdateRef.class).setName(refName).setNewValue(effectiveId).call() .get(); } return updatedRef; }
private Ref toLocal(Ref remoteRef) { Optional<String> localName = remote.mapToRemote(remoteRef.getName()); Preconditions.checkArgument(localName.isPresent(), "Can't map %s to local ref using %s", remoteRef.getName(), remote.getFetchSpec()); Ref localRef; if (remoteRef instanceof SymRef) { Ref target = toLocal(remoteRef.peel()); localRef = new SymRef(localName.get(), target); } else { localRef = new Ref(localName.get(), remoteRef.getObjectId()); } return localRef; }
final String fetch = "*".equals(branch) ? Remote.defaultRemoteRefSpec(name) : Remote.defaultMappedBranchRefSpec(name, branch); return new Remote(name, url, url, fetch, mapped, branch, username, password);
private Ref toRemote(Ref localRef) { Optional<String> remoteName = remote.mapToLocal(localRef.getName()); Preconditions.checkArgument(remoteName.isPresent(), "Can't map %s to remote ref using %s", localRef.getName(), remote.getFetchSpec()); Ref remoteRef; if (localRef instanceof SymRef) { Ref target = toRemote(localRef.peel()); remoteRef = new SymRef(remoteName.get(), target); } else { remoteRef = new Ref(remoteName.get(), localRef.getObjectId()); } return remoteRef; }
if (remote.getMapped() && !remoteRef.localName().equals(Ref.localName(remote.getMappedBranch()))) {
@Test public void testEquals() { Remote remote1 = new Remote("remote1", "fetchurl", "pushurl", "fetch", true, "mappedBranch", "username", "password"); Remote remote1_identical = new Remote("remote1", "fetchurl", "pushurl", "fetch", true, "mappedBranch", "username", "password"); Remote remote2 = new Remote("remote2", "fetchurl", "pushurl", "fetch", false, null, null, null); Remote remote2_identical = new Remote("remote2", "fetchurl", "pushurl", "fetch", false, null, null, null); assertTrue(remote1.equals(remote1)); assertFalse(remote1.equals("remote1")); assertFalse(remote1.equals(remote2)); assertFalse(remote2.equals(remote1)); assertTrue(remote1.equals(remote1_identical)); assertTrue(remote2.equals(remote2_identical)); Remote remote3 = new Remote("remote3", "fetchurl", "pushurl", "fetch", true, "mappedBranch", "username", "password"); Remote remote4 = new Remote("remote1", "fetchurl2", "pushurl", "fetch", true, "mappedBranch", "username", "password"); Remote remote5 = new Remote("remote1", "fetchurl", "pushurl2", "fetch", true, "mappedBranch", "username", "password"); Remote remote6 = new Remote("remote1", "fetchurl", "pushurl", "fetch2", true,
password = Remote.encryptPassword(password); config.put(configSection + ".password", password); return new Remote(name, url, url, fetch, mapped, branch, username, password);