Search in sources :

Example 21 with RevCommit

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

the class HooksTest method testHook.

@Test
public void testHook() throws Exception {
    // a hook that only accepts commit messages longer with at least 4 words, and converts
    // message to lower case
    CharSequence commitPreHookCode = "exception = Packages.org.locationtech.geogig.api.hooks.CannotRunGeogigOperationException;\n" + "msg = params.get(\"message\");\n" + "if (msg.length() < 30){\n" + "\tthrow new exception(\"Commit messages must have at least 30 characters\");\n}" + "params.put(\"message\", msg.toLowerCase());";
    File hooksFolder = new File(geogig.getPlatform().pwd(), ".geogig/hooks");
    File commitPreHookFile = new File(hooksFolder, "pre_commit.js");
    Files.write(commitPreHookCode, commitPreHookFile, Charsets.UTF_8);
    insertAndAdd(points1);
    try {
        geogig.command(CommitOp.class).setMessage("A short message").call();
        fail();
    } catch (Exception e) {
        String javaVersion = System.getProperty("java.version");
        // Rhino in jdk6 throws a different exception
        if (javaVersion.startsWith("1.6")) {
            String expected = "Script " + commitPreHookFile + " threw an exception";
            assertTrue(e.getMessage(), e.getMessage().contains(expected));
        } else {
            assertTrue(e.getMessage(), e.getMessage().startsWith("Commit messages must have at least 30 characters"));
        }
    }
    String longMessage = "THIS IS A LONG UPPERCASE COMMIT MESSAGE";
    RevCommit commit = geogig.command(CommitOp.class).setMessage(longMessage).call();
    assertEquals(longMessage.toLowerCase(), commit.getMessage());
}
Also used : File(java.io.File) CannotRunGeogigOperationException(org.locationtech.geogig.api.hooks.CannotRunGeogigOperationException) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 22 with RevCommit

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

the class LogOpTest method testAll.

@Test
public void testAll() 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();
    LogOp op = geogig.command(LogOp.class);
    op.addCommit(c2.getId());
    op.addCommit(c4.getId());
    Iterator<RevCommit> iterator = op.call();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertEquals(c4, iterator.next());
    assertTrue(iterator.hasNext());
    assertEquals(c3, iterator.next());
    assertTrue(iterator.hasNext());
    assertEquals(c2, iterator.next());
    assertTrue(iterator.hasNext());
    assertEquals(c1, iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 23 with RevCommit

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

the class MergeOpTest method testOctopusMergeSameFeatureChanges.

@Test
public void testOctopusMergeSameFeatureChanges() 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();
    insertAndAdd(points1_modified);
    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(points1_modified);
    RevCommit branch3 = 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())).call();
    String path = NodeRef.appendChild(pointsName, idP1);
    Optional<RevFeature> revFeature = geogig.command(RevObjectParse.class).setRefSpec(Ref.HEAD + ":" + path).call(RevFeature.class);
    assertTrue(revFeature.isPresent());
    assertEquals(RevFeatureBuilder.build(points1_modified), revFeature.get());
}
Also used : RevFeature(org.locationtech.geogig.api.RevFeature) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 24 with RevCommit

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

the class MergeOpTest method testMergeFastForward.

@Test
public void testMergeFastForward() throws Exception {
    // Create the following revision graph
    // o
    // |
    // o - master - HEAD - Points 1 added
    // .\
    // . o - branch1 - Points 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
    geogig.command(CheckoutOp.class).setSource("master").call();
    // Merge branch1 into master to create the following revision graph
    // o
    // |
    // o - Points 1 added
    // |
    // o - master - HEAD - branch1 - Points 2 added
    Ref branch1 = geogig.command(RefParse.class).setName("branch1").call().get();
    final MergeReport mergeReport = geogig.command(MergeOp.class).addCommit(Suppliers.ofInstance(branch1.getObjectId())).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());
    Iterator<RevCommit> log = geogig.command(LogOp.class).call();
    // 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) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 25 with RevCommit

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

the class PullOpTest method testPullTooManyRefs.

@Test
public void testPullTooManyRefs() throws Exception {
    // Add a commit to the remote
    insertAndAdd(remoteGeogig.geogig, lines3);
    RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
    expectedMaster.addFirst(commit);
    // Pull the commit
    PullOp pull = pull();
    pull.addRefSpec("master:newbranch:newbranch2");
    exception.expect(IllegalArgumentException.class);
    pull.setRebase(true).call();
}
Also used : PullOp(org.locationtech.geogig.api.porcelain.PullOp) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) 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