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; }
/** * 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()); }
@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()); }
assertEquals("+refs/heads/*:refs/remotes/" + remoteName1 + "/*", remote.getFetch()); remote = remoteAdd.setName(remoteName2).setURL(remoteURL2).setBranch(branch).call();