Search in sources :

Example 6 with TransferSummary

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

the class Fetch method runInternal.

/**
     * Executes the fetch command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(depth > 0 ? !fulldepth : true, "Cannot specify a depth and full depth.  Use --depth <depth> or --fulldepth.");
    if (depth > 0 || fulldepth) {
        checkParameter(cli.getGeogig().getRepository().getDepth().isPresent(), "Depth operations can only be used on a shallow clone.");
    }
    TransferSummary result;
    try {
        FetchOp fetch = cli.getGeogig().command(FetchOp.class);
        fetch.setProgressListener(cli.getProgressListener());
        fetch.setAll(all).setPrune(prune).setFullDepth(fulldepth);
        fetch.setDepth(depth);
        if (args != null) {
            for (String repo : args) {
                fetch.addRemote(repo);
            }
        }
        result = fetch.call();
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                throw new CommandFailedException("Unable to fetch, the remote history is shallow.", e);
        }
    } catch (IllegalArgumentException iae) {
        throw new CommandFailedException(iae.getMessage(), iae);
    } catch (IllegalStateException ise) {
        throw new CommandFailedException(ise.getMessage(), ise);
    }
    ConsoleReader console = cli.getConsole();
    if (result.getChangedRefs().isEmpty()) {
        console.println("Already up to date.");
    } else {
        FetchResultPrinter.print(result, console);
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) FetchOp(org.locationtech.geogig.api.porcelain.FetchOp) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 7 with TransferSummary

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

the class PushWebOp method run.

/**
     * Runs the command and builds the appropriate response.
     * 
     * @param context - the context to use for this command
     */
@Override
public void run(CommandContext context) {
    final Context geogig = this.getCommandLocator(context);
    PushOp command = geogig.command(PushOp.class);
    if (refSpec != null) {
        command.addRefSpec(refSpec);
    }
    try {
        final TransferSummary dataPushed = command.setAll(pushAll).setRemote(remoteName).call();
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeElement("Push", "Success");
                out.writeElement("dataPushed", String.valueOf(!dataPushed.isEmpty()));
                out.finish();
            }
        });
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case REMOTE_HAS_CHANGES:
                context.setResponseContent(CommandResponse.error("Push failed: The remote repository has changes that would be lost in the event of a push."));
                break;
            case HISTORY_TOO_SHALLOW:
                context.setResponseContent(CommandResponse.error("Push failed: There is not enough local history to complete the push."));
            default:
                break;
        }
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) PushOp(org.locationtech.geogig.api.porcelain.PushOp) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Aggregations

TransferSummary (org.locationtech.geogig.api.porcelain.TransferSummary)7 SynchronizationException (org.locationtech.geogig.api.porcelain.SynchronizationException)5 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 ConsoleReader (jline.console.ConsoleReader)2 Context (org.locationtech.geogig.api.Context)2 Ref (org.locationtech.geogig.api.Ref)2 FetchOp (org.locationtech.geogig.api.porcelain.FetchOp)2 PushOp (org.locationtech.geogig.api.porcelain.PushOp)2 CommandContext (org.locationtech.geogig.web.api.CommandContext)2 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)2 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)2 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 Remote (org.locationtech.geogig.api.Remote)1 DiffObjectCount (org.locationtech.geogig.api.plumbing.diff.DiffObjectCount)1 PullOp (org.locationtech.geogig.api.porcelain.PullOp)1 PullResult (org.locationtech.geogig.api.porcelain.PullResult)1 ChangedRef (org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef)1 ChangeTypes (org.locationtech.geogig.api.porcelain.TransferSummary.ChangedRef.ChangeTypes)1