Search in sources :

Example 1 with SynchronizationException

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

the class PushOpTest method testPushToRemoteHEAD.

@Test
public void testPushToRemoteHEAD() throws Exception {
    insertAndAdd(localGeogig.geogig, lines3);
    localGeogig.geogig.command(CommitOp.class).call();
    PushOp push = push();
    try {
        push.setRemote("origin").addRefSpec("HEAD").call();
        fail();
    } catch (SynchronizationException e) {
        assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode);
    }
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) Test(org.junit.Test)

Example 2 with SynchronizationException

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

the class Pull method runInternal.

/**
     * Executes the pull 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.");
    GeoGIG geogig = cli.getGeogig();
    if (depth > 0 || fulldepth) {
        if (!geogig.getRepository().getDepth().isPresent()) {
            throw new CommandFailedException("Depth operations can only be used on a shallow clone.");
        }
    }
    PullOp pull = geogig.command(PullOp.class);
    pull.setProgressListener(cli.getProgressListener());
    pull.setAll(all).setRebase(rebase).setFullDepth(fulldepth);
    pull.setDepth(depth);
    if (args != null) {
        if (args.size() > 0) {
            pull.setRemote(args.get(0));
        }
        for (int i = 1; i < args.size(); i++) {
            pull.addRefSpec(args.get(i));
        }
    }
    try {
        final PullResult result = pull.call();
        ConsoleReader console = cli.getConsole();
        TransferSummary fetchResult = result.getFetchResult();
        FetchResultPrinter.print(fetchResult, console);
        final Ref oldRef = result.getOldRef();
        final Ref newRef = result.getNewRef();
        if (oldRef == null && newRef == null) {
            console.println("Nothing to pull.");
        } else if (Objects.equal(oldRef, newRef)) {
            String name = oldRef == null ? newRef.getName() : oldRef.getName();
            name = Ref.localName(name);
            console.println(name + " already up to date.");
        } else {
            String oldTreeish;
            String newTreeish = newRef.getObjectId().toString();
            if (oldRef == null) {
                console.println("From " + result.getRemoteName());
                console.println(" * [new branch]     " + newRef.localName() + " -> " + newRef.getName());
                oldTreeish = ObjectId.NULL.toString();
            } else {
                oldTreeish = oldRef.getObjectId().toString();
            }
            DiffObjectCount count = geogig.command(DiffCount.class).setOldVersion(oldTreeish).setNewVersion(newTreeish).call();
            long added = count.getFeaturesAdded();
            long removed = count.getFeaturesRemoved();
            long modified = count.getFeaturesChanged();
            console.println(String.format("Features Added: %,d Removed: %,d Modified: %,d", added, removed, modified));
        }
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                throw new CommandFailedException("Unable to pull, the remote history is shallow.", e);
        }
    }
}
Also used : PullOp(org.locationtech.geogig.api.porcelain.PullOp) Ref(org.locationtech.geogig.api.Ref) DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) ConsoleReader(jline.console.ConsoleReader) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) PullResult(org.locationtech.geogig.api.porcelain.PullResult) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 3 with SynchronizationException

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

the class Push method runInternal.

/**
     * Executes the push command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    PushOp push = cli.getGeogig().command(PushOp.class);
    push.setProgressListener(cli.getProgressListener());
    push.setAll(all);
    if (args != null) {
        if (args.size() > 0) {
            push.setRemote(args.get(0));
        }
        for (int i = 1; i < args.size(); i++) {
            push.addRefSpec(args.get(i));
        }
    }
    try {
        // TODO: listen on progress?
        TransferSummary dataPushed = push.call();
        if (dataPushed.isEmpty()) {
            cli.getConsole().println("Nothing to push.");
        }
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case REMOTE_HAS_CHANGES:
                throw new CommandFailedException("Push failed: The remote repository has changes that would be lost in the event of a push.", e);
            case HISTORY_TOO_SHALLOW:
                throw new CommandFailedException("Push failed: There is not enough local history to complete the push.", e);
            case CANNOT_PUSH_TO_SYMBOLIC_REF:
                throw new CommandFailedException("Push failed: Cannot push to a symbolic reference", e);
            default:
                break;
        }
    }
}
Also used : PushOp(org.locationtech.geogig.api.porcelain.PushOp) TransferSummary(org.locationtech.geogig.api.porcelain.TransferSummary) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException)

Example 4 with SynchronizationException

use of org.locationtech.geogig.api.porcelain.SynchronizationException 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 5 with SynchronizationException

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

the class AbstractMappedRemoteRepo method pushNewData.

/**
     * Push all new objects from the specified {@link Ref} to the given refspec.
     * 
     * @param ref the local ref that points to new commit data
     * @param refspec the refspec to push to
     */
@Override
public void pushNewData(Ref ref, String refspec, ProgressListener progress) throws SynchronizationException {
    Optional<Ref> remoteRef = getRemoteRef(refspec);
    checkPush(ref, remoteRef);
    beginPush();
    PushCommitGatherer gatherer = new PushCommitGatherer(localRepository);
    try {
        gatherer.traverse(ref.getObjectId());
        Stack<ObjectId> needed = gatherer.commits;
        while (!needed.isEmpty()) {
            ObjectId commitToPush = needed.pop();
            pushSparseCommit(commitToPush);
        }
        ObjectId newCommitId = localRepository.graphDatabase().getMapping(ref.getObjectId());
        ObjectId originalRemoteRefValue = ObjectId.NULL;
        if (remoteRef.isPresent()) {
            originalRemoteRefValue = remoteRef.get().getObjectId();
        }
        endPush(refspec, newCommitId, originalRemoteRefValue.toString());
    } catch (Exception e) {
        Throwables.propagate(e);
    } finally {
    }
}
Also used : Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) ObjectId(org.locationtech.geogig.api.ObjectId) URISyntaxException(java.net.URISyntaxException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

SynchronizationException (org.locationtech.geogig.api.porcelain.SynchronizationException)9 TransferSummary (org.locationtech.geogig.api.porcelain.TransferSummary)5 Context (org.locationtech.geogig.api.Context)3 Ref (org.locationtech.geogig.api.Ref)3 SymRef (org.locationtech.geogig.api.SymRef)3 PushOp (org.locationtech.geogig.api.porcelain.PushOp)3 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 CommandContext (org.locationtech.geogig.web.api.CommandContext)3 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)3 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)3 Optional (com.google.common.base.Optional)2 ConsoleReader (jline.console.ConsoleReader)2 ObjectId (org.locationtech.geogig.api.ObjectId)2 FetchOp (org.locationtech.geogig.api.porcelain.FetchOp)2 PullOp (org.locationtech.geogig.api.porcelain.PullOp)2 PullResult (org.locationtech.geogig.api.porcelain.PullResult)2 FileNotFoundException (java.io.FileNotFoundException)1 URISyntaxException (java.net.URISyntaxException)1 Test (org.junit.Test)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1