Search in sources :

Example 1 with RebaseOp

use of org.locationtech.geogig.api.porcelain.RebaseOp 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)

Aggregations

GeoGIG (org.locationtech.geogig.api.GeoGIG)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 Ref (org.locationtech.geogig.api.Ref)1 CheckoutException (org.locationtech.geogig.api.porcelain.CheckoutException)1 RebaseConflictsException (org.locationtech.geogig.api.porcelain.RebaseConflictsException)1 RebaseOp (org.locationtech.geogig.api.porcelain.RebaseOp)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1