Search in sources :

Example 1 with CheckoutException

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

the class Rebase method runInternal.

/**
     * Executes the rebase command using the provided options.
     */
@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(!(skip && continueRebase), "Cannot use both --skip and --continue");
    checkParameter(!(skip && abort), "Cannot use both --skip and --abort");
    checkParameter(!(abort && continueRebase), "Cannot use both --abort and --continue");
    GeoGIG geogig = cli.getGeogig();
    RebaseOp rebase = geogig.command(RebaseOp.class).setSkip(skip).setContinue(continueRebase).setAbort(abort).setSquashMessage(squash);
    rebase.setProgressListener(cli.getProgressListener());
    if (arguments == null || arguments.size() == 0) {
        if (abort || skip || continueRebase) {
        } else {
            // Rebase onto remote branch
            throw new UnsupportedOperationException("remote branch rebase not yet supported");
        }
    } else {
        checkParameter(arguments.size() < 3, "Too many arguments specified.");
        if (arguments.size() == 2) {
            // Make sure branch is valid
            Optional<ObjectId> branchRef = geogig.command(RevParse.class).setRefSpec(arguments.get(1)).call();
            checkParameter(branchRef.isPresent(), "The branch reference could not be resolved.");
            // Checkout <branch> prior to rebase
            try {
                geogig.command(CheckoutOp.class).setSource(arguments.get(1)).call();
            } catch (CheckoutException e) {
                throw new CommandFailedException(e.getMessage(), e);
            }
        }
        Optional<Ref> upstreamRef = geogig.command(RefParse.class).setName(arguments.get(0)).call();
        checkParameter(upstreamRef.isPresent(), "The upstream reference could not be resolved.");
        rebase.setUpstream(Suppliers.ofInstance(upstreamRef.get().getObjectId()));
    }
    if (onto != null) {
        Optional<ObjectId> ontoId = geogig.command(RevParse.class).setRefSpec(onto).call();
        checkParameter(ontoId.isPresent(), "The onto reference could not be resolved.");
        rebase.setOnto(Suppliers.ofInstance(ontoId.get()));
    }
    try {
        rebase.call();
    } catch (RebaseConflictsException e) {
        StringBuilder sb = new StringBuilder();
        sb.append(e.getMessage() + "\n");
        sb.append("When you have fixed this conflicts, run 'geogig rebase --continue' to continue rebasing.\n");
        sb.append("If you would prefer to skip this commit, instead run 'geogig rebase --skip.\n");
        sb.append("To check out the original branch and stop rebasing, run 'geogig rebase --abort'\n");
        throw new CommandFailedException(sb.toString());
    }
    if (abort) {
        cli.getConsole().println("Rebase aborted successfully.");
    }
}
Also used : Ref(org.locationtech.geogig.api.Ref) ObjectId(org.locationtech.geogig.api.ObjectId) RebaseConflictsException(org.locationtech.geogig.api.porcelain.RebaseConflictsException) RebaseOp(org.locationtech.geogig.api.porcelain.RebaseOp) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) CheckoutException(org.locationtech.geogig.api.porcelain.CheckoutException)

Example 2 with CheckoutException

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

the class Checkout method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    final GeoGIG geogig = cli.getGeogig();
    checkParameter(branchOrStartPoint.size() != 0 || !paths.isEmpty(), "no branch or paths specified");
    checkParameter(branchOrStartPoint.size() < 2, "too many arguments");
    try {
        final ConsoleReader console = cli.getConsole();
        String branchOrCommit = (branchOrStartPoint.size() > 0 ? branchOrStartPoint.get(0) : null);
        CheckoutResult result = geogig.command(CheckoutOp.class).setForce(force).setSource(branchOrCommit).addPaths(paths).setOurs(ours).setTheirs(theirs).call();
        switch(result.getResult()) {
            case CHECKOUT_LOCAL_BRANCH:
                console.println("Switched to branch '" + result.getNewRef().localName() + "'");
                break;
            case CHECKOUT_REMOTE_BRANCH:
                console.println("Branch '" + result.getNewRef().localName() + "' was set up to track remote branch '" + result.getNewRef().localName() + "' from " + result.getRemoteName() + ".");
                console.println("Switched to a new branch '" + result.getNewRef().localName() + "'");
                break;
            case UPDATE_OBJECTS:
                console.println("Objects in the working tree were updated to the specifed version.");
                break;
            case DETACHED_HEAD:
                console.println("You are in 'detached HEAD' state. HEAD is now at " + result.getOid().toString().substring(0, 7) + "...");
                break;
            default:
                break;
        }
    } catch (CheckoutException e) {
        switch(e.statusCode) {
            case LOCAL_CHANGES_NOT_COMMITTED:
                throw new CommandFailedException("Working tree and index are not clean. To overwrite local changes, use the --force option", e);
            case UNMERGED_PATHS:
                throw new CommandFailedException(e.getMessage(), e);
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) CheckoutResult(org.locationtech.geogig.api.porcelain.CheckoutResult) GeoGIG(org.locationtech.geogig.api.GeoGIG) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) CheckoutException(org.locationtech.geogig.api.porcelain.CheckoutException)

Aggregations

GeoGIG (org.locationtech.geogig.api.GeoGIG)2 CheckoutException (org.locationtech.geogig.api.porcelain.CheckoutException)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 ConsoleReader (jline.console.ConsoleReader)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 Ref (org.locationtech.geogig.api.Ref)1 CheckoutResult (org.locationtech.geogig.api.porcelain.CheckoutResult)1 RebaseConflictsException (org.locationtech.geogig.api.porcelain.RebaseConflictsException)1 RebaseOp (org.locationtech.geogig.api.porcelain.RebaseOp)1