Search in sources :

Example 1 with CheckoutOp

use of org.locationtech.geogig.api.porcelain.CheckoutOp in project GeoGig by boundlessgeo.

the class CheckoutWebOp method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    if (this.getTransactionId() == null) {
        throw new CommandSpecException("No transaction was specified, checkout requires a transaction to preserve the stability of the repository.");
    }
    final Context geogig = this.getCommandLocator(context);
    CheckoutOp command = geogig.command(CheckoutOp.class);
    if (branchOrCommit != null) {
        Optional<Ref> head = geogig.command(RefParse.class).setName(Ref.HEAD).call();
        if (!head.isPresent()) {
            throw new CommandSpecException("Repository has no HEAD, can't merge.");
        }
        final String target = ((SymRef) head.get()).getTarget();
        command.setSource(branchOrCommit).call();
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeElement("OldTarget", target);
                out.writeElement("NewTarget", branchOrCommit);
                out.finish();
            }
        });
    } else if (path != null) {
        command.addPath(path);
        if (ours && !theirs) {
            command.setOurs(ours);
        } else if (theirs && !ours) {
            command.setTheirs(theirs);
        } else {
            throw new CommandSpecException("Please specify either ours or theirs to update the feature path specified.");
        }
        command.call();
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeElement("Path", path);
                out.writeElement("Strategy", ours ? "ours" : "theirs");
                out.finish();
            }
        });
    } else {
        throw new CommandSpecException("No branch or commit specified for checkout.");
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) SymRef(org.locationtech.geogig.api.SymRef) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CheckoutOp(org.locationtech.geogig.api.porcelain.CheckoutOp) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException)

Aggregations

Context (org.locationtech.geogig.api.Context)1 Ref (org.locationtech.geogig.api.Ref)1 SymRef (org.locationtech.geogig.api.SymRef)1 CheckoutOp (org.locationtech.geogig.api.porcelain.CheckoutOp)1 CommandContext (org.locationtech.geogig.web.api.CommandContext)1 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)1 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)1 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)1