Search in sources :

Example 26 with MergeScenarioReport

use of org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport in project GeoGig by boundlessgeo.

the class ReportMergeConflictsOpTest method testModifiedAndRemoved.

@Test
public void testModifiedAndRemoved() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    Feature points1Modified = feature(pointsType, idP1, "StringProp1_2", new Integer(1000), "POINT(1 1)");
    insertAndAdd(points1Modified);
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    deleteAndAdd(points1);
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class).setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit).call();
    assertEquals(1, conflicts.getConflicts().size());
    assertEquals(0, conflicts.getUnconflicted().size());
    Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class).setCommits(Lists.newArrayList(masterCommit, branchCommit)).call();
    assertTrue(hasConflicts.booleanValue());
}
Also used : ReportMergeScenarioOp(org.locationtech.geogig.api.plumbing.merge.ReportMergeScenarioOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) Feature(org.opengis.feature.Feature) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 27 with MergeScenarioReport

use of org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport in project GeoGig by boundlessgeo.

the class ReportMergeConflictsOpTest method testModifiedFeatureTypeInOneBranchEditedAttributeValueInTheOther.

@Test
public void testModifiedFeatureTypeInOneBranchEditedAttributeValueInTheOther() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    insertAndAdd(points1_modified);
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    insert(points1B);
    insert(points2);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class).setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit).call();
    assertEquals(1, conflicts.getConflicts().size());
    assertEquals(1, conflicts.getUnconflicted().size());
    Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class).setCommits(Lists.newArrayList(masterCommit, branchCommit)).call();
    assertTrue(hasConflicts.booleanValue());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ReportMergeScenarioOp(org.locationtech.geogig.api.plumbing.merge.ReportMergeScenarioOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 28 with MergeScenarioReport

use of org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport in project GeoGig by boundlessgeo.

the class ReportMergeConflictsOpTest method testModifiedDefaultFeatureTypeInBothBranches.

@Test
public void testModifiedDefaultFeatureTypeInBothBranches() throws Exception {
    insertAndAdd(points1);
    geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("TestBranch").call();
    geogig.getRepository().workingTree().updateTypeTree(pointsName, modifiedPointsType);
    insert(points1B);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    String modifiedPointsTypeSpecB = "sp:String,ip:Integer,pp:Point:srid=4326,extraB:String";
    SimpleFeatureType modifiedPointsTypeB = DataUtilities.createType(pointsNs, pointsName, modifiedPointsTypeSpecB);
    geogig.getRepository().workingTree().updateTypeTree(pointsName, modifiedPointsTypeB);
    insert(points1B);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class).setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit).call();
    // the conflict in the feature type
    assertEquals(1, conflicts.getConflicts().size());
    // the change in the feature is the
    assertEquals(0, conflicts.getUnconflicted().size());
    // same, so no conflict
    Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class).setCommits(Lists.newArrayList(masterCommit, branchCommit)).call();
    assertTrue(hasConflicts.booleanValue());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ReportMergeScenarioOp(org.locationtech.geogig.api.plumbing.merge.ReportMergeScenarioOp) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 29 with MergeScenarioReport

use of org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport 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)

Example 30 with MergeScenarioReport

use of org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport in project GeoGig by boundlessgeo.

the class PullWebOp method run.

/**
     * Runs the command and builds the appropriate response.
     * 
     * @param context - the context to use for this command
     */
@Override
public void run(CommandContext context) {
    final Context geogig = this.getCommandLocator(context);
    PullOp command = geogig.command(PullOp.class).setAuthor(authorName.orNull(), authorEmail.orNull()).setRemote(remoteName).setAll(fetchAll).addRefSpec(refSpec);
    try {
        final PullResult result = command.call();
        final Iterator<DiffEntry> iter;
        if (result.getOldRef() != null && result.getNewRef() != null && result.getOldRef().equals(result.getNewRef())) {
            iter = null;
        } else {
            if (result.getOldRef() == null) {
                iter = geogig.command(DiffOp.class).setNewVersion(result.getNewRef().getObjectId()).setOldVersion(ObjectId.NULL).call();
            } else {
                iter = geogig.command(DiffOp.class).setNewVersion(result.getNewRef().getObjectId()).setOldVersion(result.getOldRef().getObjectId()).call();
            }
        }
        context.setResponseContent(new CommandResponse() {

            @Override
            public void write(ResponseWriter out) throws Exception {
                out.start();
                out.writePullResponse(result, iter, geogig);
                out.finish();
            }
        });
    } catch (SynchronizationException e) {
        switch(e.statusCode) {
            case HISTORY_TOO_SHALLOW:
            default:
                context.setResponseContent(CommandResponse.error("Unable to pull, the remote history is shallow."));
        }
    } catch (MergeConflictsException e) {
        String[] refs = refSpec.split(":");
        String remoteRef = Ref.REMOTES_PREFIX + remoteName + "/" + refs[0];
        Optional<Ref> sourceRef = geogig.command(RefParse.class).setName(remoteRef).call();
        String destinationref = "";
        if (refs.length == 2) {
            destinationref = refs[1];
        } else {
            final Optional<Ref> currHead = geogig.command(RefParse.class).setName(Ref.HEAD).call();
            if (!currHead.isPresent()) {
                context.setResponseContent(CommandResponse.error("Repository has no HEAD, can't pull."));
            } else if (!(currHead.get() instanceof SymRef)) {
                context.setResponseContent(CommandResponse.error("Can't pull from detached HEAD"));
            }
            final SymRef headRef = (SymRef) currHead.get();
            destinationref = headRef.getTarget();
        }
        Optional<Ref> destRef = geogig.command(RefParse.class).setName(destinationref).call();
        final RevCommit theirs = context.getGeoGIG().getRepository().getCommit(sourceRef.get().getObjectId());
        final RevCommit ours = context.getGeoGIG().getRepository().getCommit(destRef.get().getObjectId());
        final Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class).setLeft(ours).setRight(theirs).call();
        context.setResponseContent(new CommandResponse() {

            final MergeScenarioReport report = geogig.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, geogig, ours.getId(), theirs.getId(), ancestor.get());
                out.finish();
            }
        });
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) PullOp(org.locationtech.geogig.api.porcelain.PullOp) Optional(com.google.common.base.Optional) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) MergeScenarioReport(org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport) PullResult(org.locationtech.geogig.api.porcelain.PullResult) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) SymRef(org.locationtech.geogig.api.SymRef) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RefParse(org.locationtech.geogig.api.plumbing.RefParse) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) RevCommit(org.locationtech.geogig.api.RevCommit)

Aggregations

RevCommit (org.locationtech.geogig.api.RevCommit)30 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)30 Test (org.junit.Test)23 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)23 ReportMergeScenarioOp (org.locationtech.geogig.api.plumbing.merge.ReportMergeScenarioOp)14 Feature (org.opengis.feature.Feature)9 AddOp (org.locationtech.geogig.api.porcelain.AddOp)8 ObjectId (org.locationtech.geogig.api.ObjectId)5 Optional (com.google.common.base.Optional)4 Ref (org.locationtech.geogig.api.Ref)4 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)4 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)4 ResponseWriter (org.locationtech.geogig.web.api.ResponseWriter)4 Context (org.locationtech.geogig.api.Context)3 SymRef (org.locationtech.geogig.api.SymRef)3 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)3 Conflict (org.locationtech.geogig.api.plumbing.merge.Conflict)3 CommandContext (org.locationtech.geogig.web.api.CommandContext)3 CommandSpecException (org.locationtech.geogig.web.api.CommandSpecException)3 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)2