Search in sources :

Example 1 with ResetMode

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

the class Reset method runInternal.

/**
     * Executes the reset command using the provided options.
     * 
     * @param cli
     * @see org.locationtech.geogig.cli.AbstractCommand#runInternal(org.locationtech.geogig.cli.GeogigCLI)
     */
@Override
public void runInternal(GeogigCLI cli) {
    final GeoGIG geogig = cli.getGeogig();
    ResetMode mode = resolveResetMode();
    ResetOp reset = cli.getGeogig().command(ResetOp.class);
    try {
        for (int i = 0; args != null && i < args.size(); i++) {
            reset.addPattern(args.get(i));
        }
        if (commit != null && commit.size() > 0) {
            Optional<ObjectId> commitId = geogig.command(RevParse.class).setRefSpec(commit.get(0)).call();
            checkParameter(commitId.isPresent(), "Commit could not be resolved.");
            reset.setCommit(Suppliers.ofInstance(commitId.get()));
        }
        reset.setMode(mode);
        reset.call();
    } catch (IllegalArgumentException iae) {
        throw new CommandFailedException(iae.getMessage(), iae);
    } catch (IllegalStateException ise) {
        throw new CommandFailedException(ise.getMessage(), ise);
    }
    if (!geogig.getRepository().workingTree().isClean()) {
        try {
            Iterator<DiffEntry> unstaged = geogig.command(DiffWorkTree.class).setFilter(null).call();
            cli.getConsole().println("Unstaged changes after reset:");
            while (unstaged.hasNext()) {
                DiffEntry entry = unstaged.next();
                ChangeType type = entry.changeType();
                switch(type) {
                    case ADDED:
                        cli.getConsole().println("A\t" + entry.newPath());
                        break;
                    case MODIFIED:
                        cli.getConsole().println("M\t" + entry.newPath());
                        break;
                    case REMOVED:
                        cli.getConsole().println("D\t" + entry.oldPath());
                        break;
                }
            }
        } catch (IOException e) {
        }
    }
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) IOException(java.io.IOException) ResetOp(org.locationtech.geogig.api.porcelain.ResetOp) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) ChangeType(org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType) ResetMode(org.locationtech.geogig.api.porcelain.ResetOp.ResetMode) GeoGIG(org.locationtech.geogig.api.GeoGIG) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Aggregations

IOException (java.io.IOException)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 ObjectId (org.locationtech.geogig.api.ObjectId)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 ChangeType (org.locationtech.geogig.api.plumbing.diff.DiffEntry.ChangeType)1 ResetOp (org.locationtech.geogig.api.porcelain.ResetOp)1 ResetMode (org.locationtech.geogig.api.porcelain.ResetOp.ResetMode)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1