Search in sources :

Example 21 with ObjectId

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

the class LsTreeOpTest method testRefAndPathListing.

@Test
public void testRefAndPathListing() {
    Iterator<NodeRef> iter = geogig.command(LsTreeOp.class).setReference("HEAD:Points").call();
    List<NodeRef> nodes = ImmutableList.copyOf(iter);
    assertEquals(3, nodes.size());
    for (NodeRef ref : nodes) {
        ObjectId metadataId = ref.getMetadataId();
        assertFalse(metadataId.isNull());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Test(org.junit.Test)

Example 22 with ObjectId

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

the class MergeOpTest method testMergeConflictingBranches.

@Test
public void testMergeConflictingBranches() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1,2 added
    // |\
    // | o - TestBranch - Points 1 modified, 2 removed, 3 added
    // |
    // o - master - HEAD - Points 1 modifiedB, 2 removed
    insertAndAdd(points1, points2);
    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)");
    insert(points1Modified);
    delete(points2);
    insert(points3);
    geogig.command(AddOp.class).call();
    RevCommit masterCommit = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("TestBranch").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insert(points1ModifiedB);
    delete(points2);
    geogig.command(AddOp.class).call();
    RevCommit branchCommit = geogig.command(CommitOp.class).call();
    // Now try to merge branch into master
    geogig.command(CheckoutOp.class).setSource("master").call();
    Ref branch = geogig.command(RefParse.class).setName("TestBranch").call().get();
    try {
        geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch.getObjectId())).call();
        fail();
    } catch (MergeConflictsException e) {
        assertTrue(e.getMessage().contains("conflict"));
    }
    Optional<Ref> ref = geogig.command(RefParse.class).setName(Ref.ORIG_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(masterCommit.getId(), ref.get().getObjectId());
    ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertTrue(ref.isPresent());
    assertEquals(branch.getObjectId(), ref.get().getObjectId());
    String msg = geogig.command(ReadMergeCommitMessageOp.class).call();
    assertFalse(Strings.isNullOrEmpty(msg));
    List<Conflict> conflicts = geogig.command(ConflictsReadOp.class).call();
    assertEquals(1, conflicts.size());
    String path = NodeRef.appendChild(pointsName, idP1);
    assertEquals(conflicts.get(0).getPath(), path);
    assertEquals(conflicts.get(0).getOurs(), RevFeatureBuilder.build(points1Modified).getId());
    assertEquals(conflicts.get(0).getTheirs(), RevFeatureBuilder.build(points1ModifiedB).getId());
    // try to commit
    try {
        geogig.command(CommitOp.class).call();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(e.getMessage(), "Cannot run operation while merge conflicts exist.");
    }
    // solve, and commit
    Feature points1Merged = feature(pointsType, idP1, "StringProp1_2", new Integer(2000), "POINT(1 1)");
    insert(points1Merged);
    geogig.command(AddOp.class).call();
    RevCommit commit = geogig.command(CommitOp.class).call();
    assertTrue(commit.getMessage().contains(idP1));
    List<ObjectId> parents = commit.getParentIds();
    assertEquals(2, parents.size());
    assertEquals(masterCommit.getId(), parents.get(0));
    assertEquals(branchCommit.getId(), parents.get(1));
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    assertEquals(RevFeatureBuilder.build(points1Merged), revFeature.get());
    path = NodeRef.appendChild(pointsName, idP2);
    revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertFalse(revFeature.isPresent());
    path = NodeRef.appendChild(pointsName, idP3);
    revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    ref = geogig.command(RefParse.class).setName(Ref.MERGE_HEAD).call();
    assertFalse(ref.isPresent());
}
Also used : AddOp(org.locationtech.geogig.api.porcelain.AddOp) ConflictsReadOp(org.locationtech.geogig.api.plumbing.merge.ConflictsReadOp) ObjectId(org.locationtech.geogig.api.ObjectId) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevFeature(org.locationtech.geogig.api.RevFeature) Feature(org.opengis.feature.Feature) 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) MergeConflictsException(org.locationtech.geogig.api.porcelain.MergeConflictsException) Conflict(org.locationtech.geogig.api.plumbing.merge.Conflict) RevFeature(org.locationtech.geogig.api.RevFeature) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevObjectParse(org.locationtech.geogig.api.plumbing.RevObjectParse) ReadMergeCommitMessageOp(org.locationtech.geogig.api.plumbing.merge.ReadMergeCommitMessageOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 23 with ObjectId

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

the class MergeOpTest method testOctopusMerge.

@Test
public void testOctopusMerge() throws Exception {
    insertAndAdd(points1);
    RevCommit initialCommit = geogig.command(CommitOp.class).call();
    geogig.command(BranchCreateOp.class).setName("branch1").call();
    geogig.command(BranchCreateOp.class).setName("branch2").call();
    geogig.command(BranchCreateOp.class).setName("branch3").call();
    geogig.command(BranchCreateOp.class).setName("branch4").call();
    geogig.command(BranchCreateOp.class).setName("branch5").call();
    geogig.command(BranchCreateOp.class).setName("branch6").call();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    ObjectId points2Id = insertAndAdd(points2);
    RevCommit branch1 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    ObjectId points3Id = insertAndAdd(points3);
    RevCommit branch2 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch3").call();
    ObjectId lines1Id = insertAndAdd(lines1);
    RevCommit branch3 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch4").call();
    ObjectId lines2Id = insertAndAdd(lines2);
    RevCommit branch4 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch5").call();
    ObjectId lines3Id = insertAndAdd(lines3);
    RevCommit branch5 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch6").call();
    ObjectId points1Id = insertAndAdd(points1_modified);
    RevCommit branch6 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getId())).addCommit(Suppliers.ofInstance(branch2.getId())).addCommit(Suppliers.ofInstance(branch3.getId())).addCommit(Suppliers.ofInstance(branch4.getId())).addCommit(Suppliers.ofInstance(branch5.getId())).addCommit(Suppliers.ofInstance(branch6.getId())).call();
    Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP1).call();
    assertTrue(ref.isPresent());
    assertEquals(points1Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP2).call();
    assertTrue(ref.isPresent());
    assertEquals(points2Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(pointsName + "/" + idP3).call();
    assertTrue(ref.isPresent());
    assertEquals(points3Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL1).call();
    assertTrue(ref.isPresent());
    assertEquals(lines1Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL2).call();
    assertTrue(ref.isPresent());
    assertEquals(lines2Id, ref.get().getNode().getObjectId());
    ref = geogig.command(FindTreeChild.class).setChildPath(linesName + "/" + idL3).call();
    assertTrue(ref.isPresent());
    assertEquals(lines3Id, ref.get().getNode().getObjectId());
    Iterator<RevCommit> log = geogig.command(LogOp.class).setFirstParentOnly(true).call();
    // MergeCommit
    RevCommit logMerge = log.next();
    assertEquals(7, logMerge.getParentIds().size());
    // Initial Commit
    RevCommit initial = log.next();
    assertEquals(initialCommit.getMessage(), initial.getMessage());
    assertEquals(initialCommit.getCommitter().getName(), initial.getCommitter().getName());
    assertEquals(initialCommit.getCommitter().getEmail(), initial.getCommitter().getEmail());
    assertEquals(initialCommit.getAuthor().getTimeZoneOffset(), initial.getAuthor().getTimeZoneOffset());
    assertEquals(initialCommit.getCommitter().getTimeZoneOffset(), initial.getCommitter().getTimeZoneOffset());
    assertEquals(initialCommit.getTreeId(), initial.getTreeId());
    assertEquals(initialCommit.getId(), initial.getId());
    assertFalse(log.hasNext());
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 24 with ObjectId

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

the class FindCommonAncestorTest method testFindCommonAncestorCase4.

@Test
public void testFindCommonAncestorCase4() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - Points 2 added
    // | |
    // | o - Points 3 added (Ancestor of branch2 and master)
    // | |\
    // | | o - Lines 1 added
    // | | |\
    // | | | o - Polygon 1 added - branch3
    // | | | |
    // | | o | - Polygon 2 added
    // | | |/
    // | | o - Merge Commit - branch2
    // | |
    // o | - Lines 2 added
    // | |
    // | o - Lines 3 added - branch1
    // |/
    // o - master - HEAD - Merge Commit
    insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // create branch1 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    insertAndAdd(points3);
    final RevCommit ancestor = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch2").call();
    insertAndAdd(lines1);
    geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch3").call();
    insertAndAdd(poly1);
    RevCommit branch3 = geogig.command(CommitOp.class).setMessage("commit for " + idPG1).call();
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    insertAndAdd(poly2);
    geogig.command(CommitOp.class).setMessage("commit for " + idPG2).call();
    MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch3.getId())).call();
    RevCommit branch2 = mergeReport.getMergeCommit();
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    insertAndAdd(lines3);
    final RevCommit left = geogig.command(CommitOp.class).setMessage("commit for " + idL3).call();
    // checkout master
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(lines2);
    geogig.command(CommitOp.class).setMessage("commit for " + idL2).call();
    mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(left.getId())).call();
    Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class).setLeft(mergeReport.getMergeCommit()).setRight(branch2).call();
    assertTrue(commonAncestor.isPresent());
    assertEquals(commonAncestor.get(), ancestor.getId());
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) ObjectId(org.locationtech.geogig.api.ObjectId) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 25 with ObjectId

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

the class FindCommonAncestorTest method testFindCommonAncestorCase5.

@Test
public void testFindCommonAncestorCase5() throws Exception {
    // Create the following revision graph
    // o - root commit Add Points 1
    // |\
    // | o - commit1 Add Points 2
    // | |\
    // o | | - commit2 Add Points 3
    // | | |
    // | | o - commit3 Modify Points 1
    // | | |
    // | o | - commit4 Add Lines 1
    // | |\|
    // | | o - commit5 Merge commit
    // | | |
    // | o | - commit6 Add Lines 2
    // | | |
    // | o | - commit7 Add Lines 3
    // | | |
    // | o | - commit8 Add Polygon 1
    // | | |
    // | o | - commit9 Add Polygon 2
    // | | |
    // | | o - commit10 Add Polygon 3
    // |/
    // o - commit11 Merge commit
    // root commit
    insertAndAdd(points1);
    geogig.command(CommitOp.class).setMessage("root commit").call();
    // commit1
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    geogig.command(CommitOp.class).setMessage("commit1").call();
    geogig.command(BranchCreateOp.class).setAutoCheckout(false).setName("branch2").call();
    // commit2
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    geogig.command(CommitOp.class).setMessage("commit2").call();
    // commit3
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    insertAndAdd(points1_modified);
    geogig.command(CommitOp.class).setMessage("commit3").call();
    // commit4
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    insertAndAdd(lines1);
    ObjectId commit4 = geogig.command(CommitOp.class).setMessage("commit4").call().getId();
    // commit5
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    geogig.command(MergeOp.class).setMessage("commit3").addCommit(Suppliers.ofInstance(commit4)).call();
    // commit6
    geogig.command(CheckoutOp.class).setSource("branch1").call();
    insertAndAdd(lines2);
    geogig.command(CommitOp.class).setMessage("commit6").call();
    // commit7
    insertAndAdd(lines3);
    geogig.command(CommitOp.class).setMessage("commit7").call();
    // commit8
    insertAndAdd(poly1);
    geogig.command(CommitOp.class).setMessage("commit8").call();
    // commit9
    insertAndAdd(poly2);
    ObjectId commit9 = geogig.command(CommitOp.class).setMessage("commit9").call().getId();
    // commit10
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    insertAndAdd(poly3);
    RevCommit commit10 = geogig.command(CommitOp.class).setMessage("commit10").call();
    // commit11
    geogig.command(CheckoutOp.class).setSource("master").call();
    MergeReport report = geogig.command(MergeOp.class).setMessage("commit11").addCommit(Suppliers.ofInstance(commit9)).call();
    Optional<ObjectId> commonAncestor = geogig.command(FindCommonAncestor.class).setLeft(report.getMergeCommit()).setRight(commit10).call();
    assertTrue(commonAncestor.isPresent());
    assertEquals(commonAncestor.get(), commit4);
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) ObjectId(org.locationtech.geogig.api.ObjectId) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22