Search in sources :

Example 6 with MergeOp

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

the class MergeOpTest method testConflictingOctopusMerge.

@Test
public void testConflictingOctopusMerge() throws Exception {
    // Create the following revision graph
    // . o
    // . |
    // . o - Points 1 added
    // . |\
    // . | o - branch1 - Points 1 modified
    // . |
    // . o - Points 2 added
    // ./|
    // o | - branch2 - Point 1 modified B
    // . |
    // . o - master - HEAD - Point 1 modified C
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch1").call();
    insertAndAdd(points2);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch2").call();
    Feature points1ModifiedC = feature(pointsType, idP1, "StringProp1_4", new Integer(3000), "POINT(1 3)");
    insertAndAdd(points1ModifiedC);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insertAndAdd(points1Modified);
    geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 2)");
    insertAndAdd(points1ModifiedB);
    geogig.command(CommitOp.class).call();
    // Now try to merge all branches into master
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    Ref branch2 = geogig.command(RefParse.class).setName("branch2").call().get();
    MergeOp mergeOp = geogig.command(MergeOp.class);
    mergeOp.addCommit(Suppliers.ofInstance(branch1.getObjectId()));
    mergeOp.addCommit(Suppliers.ofInstance(branch2.getObjectId()));
    try {
        mergeOp.call();
        fail();
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("Cannot merge more than two commits when conflicts exist"));
    }
}
Also used : UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) NodeRef(org.locationtech.geogig.api.NodeRef) RefParse(org.locationtech.geogig.api.plumbing.RefParse) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 7 with MergeOp

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

the class MergeWebOp method run.

/**
     * Runs the command and builds the appropriate response.
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    if (this.getTransactionId() == null) {
        throw new CommandSpecException("No transaction was specified, merge requires a transaction to preserve the stability of the repository.");
    } else if (this.commit == null) {
        throw new CommandSpecException("No commits were specified for merging.");
    }
    final GeogigTransaction transaction = (GeogigTransaction) this.getCommandLocator(context);
    final Optional<Ref> currHead = transaction.command(RefParse.class).setName(Ref.HEAD).call();
    if (!currHead.isPresent()) {
        throw new CommandSpecException("Repository has no HEAD, can't merge.");
    }
    MergeOp merge = transaction.command(MergeOp.class);
    merge.setAuthor(authorName.orNull(), authorEmail.orNull());
    final Optional<ObjectId> oid = transaction.command(RevParse.class).setRefSpec(commit).call();
    if (oid.isPresent()) {
        merge.addCommit(Suppliers.ofInstance(oid.get()));
    } else {
        throw new CommandSpecException("Couldn't resolve '" + commit + "' to a commit.");
    }
    try {
        final MergeReport report = merge.setNoCommit(noCommit).call();
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writeMergeResponse(Optional.fromNullable(report.getMergeCommit()), report.getReport().get(), transaction, report.getOurs(), report.getPairs().get(0).getTheirs(), report.getPairs().get(0).getAncestor());
                out.finish();
            }
        });
    } catch (Exception e) {
        final RevCommit ours = context.getGeoGIG().getRepository().getCommit(currHead.get().getObjectId());
        final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(oid.get());
        final Optional<ObjectId> ancestor = transaction.command(FindCommonAncestor.class).setLeft(ours).setRight(theirs).call();
        context.setResponseContent(new CommandResponse() {

            final MergeScenarioReport report = transaction.command(ReportMergeScenarioOp.class).setMergeIntoCommit(ours).setToMergeCommit(theirs).call();

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                Optional<RevCommit> mergeCommit = Optional.absent();
                out.writeMergeResponse(mergeCommit, report, transaction, ours.getId(), theirs.getId(), ancestor.get());
                out.finish();
            }
        });
    }
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) Ref(org.locationtech.geogig.api.Ref) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevCommit(org.locationtech.geogig.api.RevCommit)

Aggregations

MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)7 RevCommit (org.locationtech.geogig.api.RevCommit)6 ObjectId (org.locationtech.geogig.api.ObjectId)5 MergeReport (org.locationtech.geogig.api.porcelain.MergeOp.MergeReport)5 Test (org.junit.Test)4 Ref (org.locationtech.geogig.api.Ref)4 Feature (org.opengis.feature.Feature)4 Optional (com.google.common.base.Optional)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 NodeRef (org.locationtech.geogig.api.NodeRef)2 RevFeature (org.locationtech.geogig.api.RevFeature)2 RevObject (org.locationtech.geogig.api.RevObject)2 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)2 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)2 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)2 LogOp (org.locationtech.geogig.api.porcelain.LogOp)2 PushOp (org.locationtech.geogig.api.porcelain.PushOp)2 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)2