Search in sources :

Example 56 with RevCommit

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

the class MergeOpTest method testMerge.

@Test
public void testMerge() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // |
    // o - Points 3 added
    // |
    // o - master - HEAD - Lines 1 added
    insertAndAdd(points1);
    final RevCommit c1 = geogig.command(CommitOp.class).setMessage("commit for " + idP1).call();
    // create branch1 and checkout
    geogig.command(BranchCreateOp.class).setAutoCheckout(true).setName("branch1").call();
    insertAndAdd(points2);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    // checkout master
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    final RevCommit c3 = geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    // Merge branch1 into master to create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // | |
    // o | - Points 3 added
    // | |
    // o | - Lines 1 added
    // |/
    // o - master - HEAD - Merge commit
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).setMessage("My merge message.").call();
    RevTree mergedTree = repo.getTree(mergeReport.getMergeCommit().getTreeId());
    String path = appendChild(pointsName, points2.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(pointsName, points3.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    path = appendChild(linesName, lines1.getIdentifier().getID());
    assertTrue(repo.command(FindTreeChild.class).setParent(mergedTree).setChildPath(path).call().isPresent());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // Merge Commit
    RevCommit logCmerge = log.next();
    assertEquals("My merge message.", logCmerge.getMessage());
    assertEquals(2, logCmerge.getParentIds().size());
    assertEquals(c4.getId(), logCmerge.getParentIds().get(0));
    assertEquals(c2.getId(), logCmerge.getParentIds().get(1));
    // Commit 4
    RevCommit logC4 = log.next();
    assertEquals(c4.getAuthor(), logC4.getAuthor());
    assertEquals(c4.getCommitter(), logC4.getCommitter());
    assertEquals(c4.getMessage(), logC4.getMessage());
    assertEquals(c4.getTreeId(), logC4.getTreeId());
    // Commit 3
    RevCommit logC3 = log.next();
    assertEquals(c3.getAuthor(), logC3.getAuthor());
    assertEquals(c3.getCommitter(), logC3.getCommitter());
    assertEquals(c3.getMessage(), logC3.getMessage());
    assertEquals(c3.getTreeId(), logC3.getTreeId());
    // Commit 2
    RevCommit logC2 = log.next();
    assertEquals(c2.getAuthor(), logC2.getAuthor());
    assertEquals(c2.getCommitter(), logC2.getCommitter());
    assertEquals(c2.getMessage(), logC2.getMessage());
    assertEquals(c2.getTreeId(), logC2.getTreeId());
    // Commit 1
    RevCommit logC1 = log.next();
    assertEquals(c1.getAuthor(), logC1.getAuthor());
    assertEquals(c1.getCommitter(), logC1.getCommitter());
    assertEquals(c1.getMessage(), logC1.getMessage());
    assertEquals(c1.getTreeId(), logC1.getTreeId());
}
Also used : MergeReport(org.locationtech.geogig.api.porcelain.MergeOp.MergeReport) 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) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) MergeOp(org.locationtech.geogig.api.porcelain.MergeOp) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 57 with RevCommit

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

the class MergeOpTest method testSpecifyAuthor.

@Test
public void testSpecifyAuthor() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // |
    // o - Points 3 added
    // |
    // o - master - HEAD - Lines 1 added
    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);
    final RevCommit c2 = geogig.command(CommitOp.class).setMessage("commit for " + idP2).call();
    // checkout master
    geogig.command(CheckoutOp.class).setSource("master").call();
    insertAndAdd(points3);
    geogig.command(CommitOp.class).setMessage("commit for " + idP3).call();
    insertAndAdd(lines1);
    final RevCommit c4 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    // Merge branch1 into master to create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - branch1 - Points 2 added
    // | |
    // o | - Points 3 added
    // | |
    // o | - Lines 1 added
    // |/
    // o - master - HEAD - Merge commit
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    geogig.command(MergeOp.class).setAuthor("Merge Author", "merge@author.com").addCommit(Suppliers.ofInstance(branch1.getObjectId())).setMessage("My merge message.").call();
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // Merge Commit
    RevCommit logCmerge = log.next();
    assertEquals("My merge message.", logCmerge.getMessage());
    assertEquals("Merge Author", logCmerge.getAuthor().getName().get());
    assertEquals("merge@author.com", logCmerge.getAuthor().getEmail().get());
    assertEquals(2, logCmerge.getParentIds().size());
    assertEquals(c4.getId(), logCmerge.getParentIds().get(0));
    assertEquals(c2.getId(), logCmerge.getParentIds().get(1));
}
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) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RefParse(org.locationtech.geogig.api.plumbing.RefParse) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 58 with RevCommit

use of org.locationtech.geogig.api.RevCommit 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 59 with RevCommit

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

the class MergeOpTest method testOctopusMergeWithAutomerge.

@Test
public void testOctopusMergeWithAutomerge() throws Exception {
    insertAndAdd(points1);
    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();
    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("branch1").call();
    insertAndAdd(points2);
    RevCommit branch1 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch2").call();
    insertAndAdd(points3);
    RevCommit branch2 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch3").call();
    insertAndAdd(lines1);
    RevCommit branch3 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch4").call();
    insertAndAdd(lines2);
    RevCommit branch4 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch5").call();
    insertAndAdd(lines3);
    RevCommit branch5 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("branch6").call();
    Feature points1ModifiedB = feature(pointsType, idP1, "StringProp1_3", new Integer(2000), "POINT(1 1)");
    insertAndAdd(points1ModifiedB);
    RevCommit branch6 = geogig.command(CommitOp.class).call();
    geogig.command(CheckoutOp.class).setSource("master").call();
    MergeOp mergeOp = 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()));
    try {
        mergeOp.call();
        fail();
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("Cannot merge more than two commits when conflicts exist"));
    }
}
Also used : 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) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 60 with RevCommit

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

Aggregations

RevCommit (org.locationtech.geogig.api.RevCommit)291 Test (org.junit.Test)212 ObjectId (org.locationtech.geogig.api.ObjectId)109 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)107 LogOp (org.locationtech.geogig.api.porcelain.LogOp)86 Ref (org.locationtech.geogig.api.Ref)71 Feature (org.opengis.feature.Feature)52 NodeRef (org.locationtech.geogig.api.NodeRef)47 ArrayList (java.util.ArrayList)44 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)44 RevTree (org.locationtech.geogig.api.RevTree)36 SymRef (org.locationtech.geogig.api.SymRef)33 RefParse (org.locationtech.geogig.api.plumbing.RefParse)33 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)31 RevObject (org.locationtech.geogig.api.RevObject)30 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)30 MergeScenarioReport (org.locationtech.geogig.api.plumbing.merge.MergeScenarioReport)30 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)26 LinkedList (java.util.LinkedList)24 AddOp (org.locationtech.geogig.api.porcelain.AddOp)21