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.");
}
}
Aggregations