Search in sources :

Example 1 with MergeReport

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

the class MergeOpTest method testMergeMultiple.

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

Example 2 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport 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 3 with MergeReport

use of org.locationtech.geogig.api.porcelain.MergeOp.MergeReport 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 4 with MergeReport

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

Example 5 with MergeReport

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

the class FindCommonAncestorTest method testFindCommonAncestorCase3.

@Test
public void testFindCommonAncestorCase3() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |\
    // | o - Points 2 added
    // | |
    // | o - Points 3 added
    // | |\
    // | | o - Lines 1 added - 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);
    final RevCommit branch2 = geogig.command(CommitOp.class).setMessage("commit for " + idL1).call();
    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();
    final MergeReport 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) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

MergeReport (org.locationtech.geogig.api.porcelain.MergeOp.MergeReport)21 RevCommit (org.locationtech.geogig.api.RevCommit)19 Test (org.junit.Test)16 Ref (org.locationtech.geogig.api.Ref)14 BranchCreateOp (org.locationtech.geogig.api.porcelain.BranchCreateOp)13 MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)13 RefParse (org.locationtech.geogig.api.plumbing.RefParse)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 LogOp (org.locationtech.geogig.api.porcelain.LogOp)9 NodeRef (org.locationtech.geogig.api.NodeRef)8 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)7 RevTree (org.locationtech.geogig.api.RevTree)6 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)6 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)5 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 FindCommonAncestor (org.locationtech.geogig.api.plumbing.FindCommonAncestor)3 Optional (com.google.common.base.Optional)2 HashMap (java.util.HashMap)2 RevObject (org.locationtech.geogig.api.RevObject)2