private Remote addRemote(Repository clone) { final boolean sparse = clone.isSparse(); if (sparse || singleBranch) { 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(); RemoteAddOp cmd = clone.command(RemoteAddOp.class)// .setName(remoteName)// .setURL(remoteURI.toString())// .setMapped(sparse)// .setUserName(username)// .setPassword(password); if (sparse || singleBranch) { cmd.setBranch(branch); } Remote remote = cmd.call(); return remote; }
/** * 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); } } }
/** * 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 testEmptyName() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); exception.expect(RemoteException.class); remoteAdd.setName("").setURL("http://test.com").call(); }
@Test public void testNullURL() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); exception.expect(RemoteException.class); remoteAdd.setName("myremote").setURL(null).call(); }
@Test public void testNullName() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); exception.expect(RemoteException.class); remoteAdd.setName(null).setURL("http://test.com").call(); }
@Test public void testEmptyURL() { final RemoteAddOp remoteAdd = geogig.command(RemoteAddOp.class); exception.expect(RemoteException.class); remoteAdd.setName("myremote").setURL("").call(); }
@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(); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); exception.expect(RemoteException.class); remoteAdd.setName(remoteName).setURL("someotherurl.com").call(); }
@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(Remote.defaultRemoteRefSpec(remoteName1), remote.getFetchSpec()); remote = remoteAdd.setName(remoteName2).setURL(remoteURL2).call(); assertEquals(remoteName2, remote.getName()); assertEquals(remoteURL2, remote.getFetchURL()); assertEquals(remoteURL2, remote.getPushURL()); }
@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 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.getFetchSpec()); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); 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()); }
@Test public void testListRemoteWithNoFetch() { 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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); final ConfigOp config = geogig.command(ConfigOp.class); config.setAction(ConfigAction.CONFIG_UNSET).setName("remote." + remoteName + ".fetch") .call(); final RemoteListOp remoteList = geogig.command(RemoteListOp.class); ImmutableList<Remote> allRemotes = remoteList.call(); assertTrue(allRemotes.isEmpty()); } }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); final RemoteRemoveOp remoteRemove = geogig.command(RemoteRemoveOp.class); exception.expect(RemoteException.class); remoteRemove.setName("nonexistent").call(); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); 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(Remote.defaultRemoteRefSpec(remoteName), deletedRemote.getFetchSpec()); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); 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(Remote.defaultRemoteRefSpec(remoteName), deletedRemote.getFetchSpec()); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); 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(Remote.defaultRemoteRefSpec(remoteName), deletedRemote.getFetchSpec()); }
@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(Remote.defaultRemoteRefSpec(remoteName), remote.getFetchSpec()); 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.getFetchSpec()); } }