private void remoteRemove(CommandContext context, final Context geogig) { if (remoteName == null || remoteName.trim().isEmpty()) { throw new CommandSpecException("No remote was specified."); } final Remote remote; try { remote = geogig.command(RemoteRemoveOp.class).setName(remoteName).call(); } catch (RemoteException e) { throw new CommandSpecException(e.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(); } }); }
throw new RemoteException(StatusCode.MISSING_NAME); ConfigDatabase config = configDatabase(); List<String> allRemotes = config.getAllSubsections("remote"); if (!allRemotes.contains(name)) { final ImmutableSet<Ref> localRemoteRefs = command(LsRemoteOp.class).retrieveLocalRefs(true) .setRemote(Suppliers.ofInstance(Optional.of(remote))).call(); command(UpdateRef.class).setDelete(true).setName(localRef.getName()).call();
@Override String params(RemoteRemoveOp c) { return format("name='%s'", c.getName()); } }
/** * Executes the remote remove command. */ @Override public void runInternal(GeogigCLI cli) { if (params == null || params.size() != 1) { printUsage(cli); throw new CommandFailedException(); } try { cli.getGeogig().command(RemoteRemoveOp.class).setName(params.get(0)).call(); } catch (RemoteException e) { switch (e.statusCode) { case REMOTE_NOT_FOUND: throw new InvalidParameterException( "Could not find a remote called '" + params.get(0) + "'.", e); default: throw new CommandFailedException(e.getMessage(), e); } } }
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(); } }); }
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; }
String name = deleted.getName(); try { geogig.command(RemoteRemoveOp.class).setName(name).call(); } catch (RuntimeException e) { throw new RuntimeException("Error deleting remote " + name, e); geogig.command(RemoteRemoveOp.class).setName(old.getName()).call(); RemoteAddOp addop = geogig.command(RemoteAddOp.class); addop.setName(ri.getName())
@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 testRemoveRemote() { 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); Remote deletedRemote = remoteRemove.setName(remoteName).call(); assertEquals(remoteName, deletedRemote.getName()); assertEquals(remoteURL, deletedRemote.getFetchURL()); assertEquals(remoteURL, deletedRemote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", deletedRemote.getFetch()); }
@Test public void testRemoveRemoteWithRefs() { 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()); String refName = Ref.REMOTES_PREFIX + remoteName + "/branch1"; geogig.command(UpdateRef.class).setName(refName).setNewValue(ObjectId.NULL).call(); final RemoteRemoveOp remoteRemove = geogig.command(RemoteRemoveOp.class); Remote deletedRemote = remoteRemove.setName(remoteName).call(); Optional<Ref> remoteRef = geogig.command(RefParse.class).setName(refName).call(); assertFalse(remoteRef.isPresent()); assertEquals(remoteName, deletedRemote.getName()); assertEquals(remoteURL, deletedRemote.getFetchURL()); assertEquals(remoteURL, deletedRemote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", deletedRemote.getFetch()); }
@Test public void testRemoveRemoteWithNoURL() { 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 RemoteRemoveOp remoteRemove = geogig.command(RemoteRemoveOp.class); Remote deletedRemote = remoteRemove.setName(remoteName).call(); assertEquals(remoteName, deletedRemote.getName()); assertEquals("", deletedRemote.getFetchURL()); assertEquals("", deletedRemote.getPushURL()); assertEquals("+refs/heads/*:refs/remotes/" + remoteName + "/*", deletedRemote.getFetch()); }
@Test public void testRemoveRemoteWithNoFetch() { 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 + ".fetch") .call(); final RemoteRemoveOp remoteRemove = geogig.command(RemoteRemoveOp.class); Remote deletedRemote = remoteRemove.setName(remoteName).call(); assertEquals(remoteName, deletedRemote.getName()); assertEquals(remoteURL, deletedRemote.getFetchURL()); assertEquals(remoteURL, deletedRemote.getPushURL()); assertEquals("", deletedRemote.getFetch()); } }