/** * Executes the remote add command using the provided options. */ @Override public void runInternal(GeogigCLI cli) { if (params == null || params.size() != 2) { printUsage(cli); throw new CommandFailedException(); } try { cli.getGeogig().command(RemoteAddOp.class).setName(params.get(0)).setURL(params.get(1)) .setBranch(branch).setUserName(username).setPassword(password).call(); } catch (RemoteException e) { switch (e.statusCode) { case REMOTE_ALREADY_EXISTS: throw new InvalidParameterException( "Could not add, a remote called '" + params.get(0) + "' already exists.", e); default: throw new CommandFailedException(e); } } }
@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 testAddRemoteEmptyBranch() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).setBranch("").call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", remote.getFetch()); }
private Remote addRemote(Repository clone) { final boolean sparse = clone.isSparse(); if (sparse) { checkArgument(this.branch.isPresent(), "No branch specified for sparse clone."); } {// won't be necessary once ClopeOp actually creates the clone repo Optional<Remote> remote = clone.command(RemoteResolve.class).setName(remoteName).call(); if (remote.isPresent()) { clone.command(RemoteRemoveOp.class).setName(remoteName).call(); } } final @Nullable String branch = this.branch.orNull(); Remote remote = clone.command(RemoteAddOp.class)// .setName(remoteName)// .setURL(remoteURI.toString())// .setMapped(sparse)// .setUserName(username)// .setPassword(password)// .setBranch(branch).// call(); return remote; }
@Test public void testAddRemoteWithBranch() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; String branch = "mybranch"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).setBranch(branch).call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals("+refs/heads/" + branch + ":refs/remotes/" + remoteName + "/" + branch, remote.getFetch()); }
private void remoteAdd(CommandContext context, final Context geogig) { if (remoteName == null || remoteName.trim().isEmpty()) { throw new CommandSpecException("No remote was specified."); } else if (remoteURL == null || remoteURL.trim().isEmpty()) { throw new CommandSpecException("No URL was specified."); } final Remote remote; try { remote = geogig.command(RemoteAddOp.class).setName(remoteName).setURL(remoteURL) .setUserName(username).setPassword(password).call(); } catch (RemoteException re) { throw new CommandSpecException(re.statusCode.toString(), HttpStatus.BAD_REQUEST); } context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeElement("name", remote.getName()); out.finish(); } }); }
private void remoteUpdate(CommandContext context, final Context geogig) { if (remoteName == null || remoteName.trim().isEmpty()) { throw new CommandSpecException("No remote was specified."); } else if (remoteURL == null || remoteURL.trim().isEmpty()) { throw new CommandSpecException("No URL was specified."); } final Remote newRemote; if (newName != null && !newName.trim().isEmpty() && !newName.equals(remoteName)) { newRemote = geogig.command(RemoteAddOp.class).setName(newName).setURL(remoteURL) .setUserName(username).setPassword(password).call(); geogig.command(RemoteRemoveOp.class).setName(remoteName).call(); } else { geogig.command(RemoteRemoveOp.class).setName(remoteName).call(); newRemote = geogig.command(RemoteAddOp.class).setName(remoteName).setURL(remoteURL) .setUserName(username).setPassword(password).call(); } context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeElement("name", newRemote.getName()); out.finish(); } }); }
@Test public void testInvalidName() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); exception.expect(IllegalArgumentException.class); exception.expectMessage("Component of ref cannot have two consecutive dots (..) anywhere."); remoteAdd.setName("ma..er").setURL("http://test.com").call(); }
if (ri.getId() == null) { // its a new one RemoteAddOp cmd = geogig.command(RemoteAddOp.class); cmd.setName(ri.getName()); cmd.setURL(ri.getURL()); cmd.setUserName(ri.getUserName()); cmd.setPassword(ri.getPassword()); try { cmd.call(); } catch (RuntimeException e) { throw new RuntimeException( geogig.command(RemoteRemoveOp.class).setName(old.getName()).call(); RemoteAddOp addop = geogig.command(RemoteAddOp.class); addop.setName(ri.getName()) .setURL(ri.getURL()) .setUserName(ri.getUserName()) .setPassword(ri.getPassword()); addop.call(); } catch (RuntimeException e) { throw new RuntimeException(
@Test public void testAddRemoteThatExists() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", remote.getFetch()); exception.expect(RemoteException.class); remoteAdd.setName(remoteName).setURL("someotherurl.com").call(); }
@Given("^There are three repos with remotes$") public void twoGoodRepos() throws Throwable { Repository repo2 = context.createRepo("repo2").init("geogigUser", "repo_Owner@geogig.org") .getRepo(); Repository repo3 = context.createRepo("repo3").init("geogigUser", "repo_Owner@geogig.org") .getRepo(); String repo2Url = repo2.getLocation().toString(); repo3.command(RemoteAddOp.class).setName("repo2").setURL(repo2Url).call(); Repository repo4 = context.createRepo("repo4").init("geogigUser", "repo_Owner@geogig.org") .getRepo(); repo4.command(RemoteAddOp.class).setName("repo2").setURL(repo2Url).call(); repo2.close(); repo3.close(); repo4.close(); openedRepos.add("repo1"); openedRepos.add("repo2"); openedRepos.add("repo3"); openedRepos.add("repo4"); }
@Test public void testAddMultipleRemotes() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName1 = "myremote"; String remoteURL1 = "http://test.com"; String remoteName2 = "myremote2"; String remoteURL2 = "http://test2.org"; Remote remote = remoteAdd.setName(remoteName1).setURL(remoteURL1).call(); assertEquals(remoteName1, remote.getName()); assertEquals(remoteURL1, remote.getFetchURL()); assertEquals(remoteURL1, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName1 + "/*", remote.getFetch()); remote = remoteAdd.setName(remoteName2).setURL(remoteURL2).call(); assertEquals(remoteName2, remote.getName()); assertEquals(remoteURL2, remote.getFetchURL()); assertEquals(remoteURL2, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName2 + "/*", remote.getFetch()); }
Remote originInfo = localGeogig.geogig.command(RemoteAddOp.class).setName(REMOTE_NAME) .setURL(remoteURI).call(); Repository originRepo = remoteGeogig.geogig.getRepository(); localGeogig.addRemoteOverride(originInfo, originRepo); originInfo = upstreamGeogig.geogig.command(RemoteAddOp.class).setName(REMOTE_NAME) .setURL(remoteURI).call(); upstreamGeogig.addRemoteOverride(originInfo, originRepo);
@Test public void testRemoveNonexistentRemote() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", remote.getFetch()); final RemoteRemoveOp remoteRemove = geogig.command(RemoteRemoveOp.class); exception.expect(RemoteException.class); remoteRemove.setName("nonexistent").call(); }
@Test public void testListRemoteWithNoURL() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); String remoteName = "myremote"; String remoteURL = "http://test.com"; Remote remote = remoteAdd.setName(remoteName).setURL(remoteURL).call(); assertEquals(remoteName, remote.getName()); assertEquals(remoteURL, remote.getFetchURL()); assertEquals(remoteURL, remote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", remote.getFetch()); final ConfigOp config = geogig.command(ConfigOp.class); config.setAction(ConfigAction.CONFIG_UNSET).setName("remote." + remoteName + ".url").call(); final RemoteListOp remoteList = geogig.command(RemoteListOp.class); ImmutableList<Remote> allRemotes = remoteList.call(); assertTrue(allRemotes.isEmpty()); }