Package org.locationtech.geogig.api

Examples of org.locationtech.geogig.api.Remote


        ProgressListener progressListener = getProgressListener();
        progressListener.started();

        // Set up origin
        Remote remote = command(RemoteAddOp.class).setName("origin").setURL(repositoryURL)
                .setMapped(repository.isSparse()).setUserName(username).setPassword(password)
                .setBranch(repository.isSparse() ? branch.get() : null).call();

        if (!depth.isPresent()) {
            // See if we are cloning a shallow clone. If so, a depth must be specified.
            Optional<IRemoteRepo> remoteRepo = RemoteUtils.newRemote(
                    GlobalContextBuilder.builder.build(Hints.readOnly()), remote, repository,
                    repository.deduplicationService());

            Preconditions.checkState(remoteRepo.isPresent(), "Failed to connect to the remote.");
            IRemoteRepo remoteRepoInstance = remoteRepo.get();
            try {
                remoteRepoInstance.open();
            } catch (IOException e) {
                Throwables.propagate(e);
            }
            try {
                depth = remoteRepoInstance.getDepth();
            } finally {
                try {
                    remoteRepoInstance.close();
                } catch (IOException e) {
                    Throwables.propagate(e);
                }
            }
        }

        if (depth.isPresent()) {
            command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setScope(ConfigScope.LOCAL)
                    .setName(Repository.DEPTH_CONFIG_KEY).setValue(depth.get().toString()).call();
        }

        // Fetch remote data
        command(FetchOp.class).setDepth(depth.or(0)).setProgressListener(progressListener).call();

        // Set up remote tracking branches
        final ImmutableSet<Ref> remoteRefs = command(LsRemote.class).retrieveTags(false)
                .setRemote(Suppliers.ofInstance(Optional.of(remote))).call();

        boolean emptyRepo = true;

        for (Ref remoteRef : remoteRefs) {
            if (emptyRepo && !remoteRef.getObjectId().isNull()) {
                emptyRepo = false;
            }
            String branchName = remoteRef.localName();
            if (remoteRef instanceof SymRef) {
                continue;
            }
            if (!command(RefParse.class).setName(Ref.HEADS_PREFIX + branchName).call().isPresent()) {
                command(BranchCreateOp.class).setName(branchName)
                        .setSource(remoteRef.getObjectId().toString()).call();
            } else {
                command(UpdateRef.class).setName(Ref.HEADS_PREFIX + branchName)
                        .setNewValue(remoteRef.getObjectId()).call();
            }

            command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setScope(ConfigScope.LOCAL)
                    .setName("branches." + branchName + ".remote").setValue(remote.getName())
                    .call();

            command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setScope(ConfigScope.LOCAL)
                    .setName("branches." + branchName + ".merge")
                    .setValue(Ref.HEADS_PREFIX + remoteRef.localName()).call();
        }

        if (!emptyRepo) {
            // checkout branch
            if (branch.isPresent()) {
                command(CheckoutOp.class).setForce(true).setSource(branch.get()).call();
            } else {
                // checkout the head
                final Optional<Ref> currRemoteHead = command(RefParse.class).setName(
                        Ref.REMOTES_PREFIX + remote.getName() + "/" + Ref.HEAD).call();
                if (currRemoteHead.isPresent() && currRemoteHead.get() instanceof SymRef) {
                    final SymRef remoteHeadRef = (SymRef) currRemoteHead.get();
                    final String currentBranch = Ref.localName(remoteHeadRef.getTarget());
                    command(CheckoutOp.class).setForce(true).setSource(currentBranch).call();
                } else {
View Full Code Here


        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();
            context.setResponseContent(new CommandResponse() {
                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeElement("name", remote.getName());
                    out.finish();
                }
            });
        } catch (RemoteException e) {
            context.setResponseContent(CommandResponse.error(e.statusCode.toString()));
View Full Code Here

        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;
        try {
            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();
                }
            });
        } catch (RemoteException e) {
            context.setResponseContent(CommandResponse.error(e.statusCode.toString()));
View Full Code Here

    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) {
            context.setResponseContent(CommandResponse.error(e.statusCode.toString()));
            return;
        } catch (Exception e) {
            context.setResponseContent(CommandResponse.error("Aborting Remote Remove"));
            return;
        }
        context.setResponseContent(new CommandResponse() {
            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeElement("name", remote.getName());
                out.finish();
            }
        });
    }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.api.Remote

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.