Search in sources :

Example 66 with RevCommit

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

the class PullOpTest method testPullToCurrentBranch.

@Test
public void testPullToCurrentBranch() throws Exception {
    // Add a commit to the remote
    insertAndAdd(remoteGeogig.geogig, lines3);
    RevCommit commit = remoteGeogig.geogig.command(CommitOp.class).call();
    expectedMaster.addFirst(commit);
    // Make sure the local master matches the remote
    localGeogig.geogig.command(BranchCreateOp.class).setName("mynewbranch").setAutoCheckout(true).call();
    // Pull the commit
    PullOp pull = pull();
    pull.addRefSpec("master");
    pull.setRebase(true).call();
    final Optional<Ref> currHead = localGeogig.geogig.command(RefParse.class).setName(Ref.HEAD).call();
    assertTrue(currHead.isPresent());
    assertTrue(currHead.get() instanceof SymRef);
    final SymRef headRef = (SymRef) currHead.get();
    final String currentBranch = Ref.localName(headRef.getTarget());
    assertEquals("mynewbranch", currentBranch);
    Iterator<RevCommit> logs = localGeogig.geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedMaster, logged);
}
Also used : PullOp(org.locationtech.geogig.api.porcelain.PullOp) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 67 with RevCommit

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

the class GeogigTransactionTest method testCommitUpdatesRemoteRefs.

@Test
public void testCommitUpdatesRemoteRefs() throws Exception {
    // make a commit
    insertAndAdd(points1);
    RevCommit headCommit = geogig.command(CommitOp.class).call();
    geogig.command(RemoteAddOp.class).setName("upstream").setURL("http://test.com/geogig/upstream").call();
    final String remoteRef = "refs/remotes/upstream/master";
    final String unchangedRemoteRef = "refs/remotes/upstream/testbranch";
    Ref remoteHead = geogig.command(UpdateRef.class).setName(remoteRef).setNewValue(headCommit.getId()).call().get();
    assertEquals(headCommit.getId(), remoteHead.getObjectId());
    geogig.command(UpdateRef.class).setName(unchangedRemoteRef).setNewValue(headCommit.getId()).call().get();
    // start a transaction
    GeogigTransaction tx = geogig.command(TransactionBegin.class).call();
    // make a commit
    insertAndAdd(tx, points2);
    RevCommit newcommit = tx.command(CommitOp.class).call();
    // upadte remote
    Ref txRemoteHead = tx.command(UpdateRef.class).setName(remoteRef).setNewValue(newcommit.getId()).call().get();
    assertEquals(newcommit.getId(), txRemoteHead.getObjectId());
    // commit transaction
    tx.commit();
    txRemoteHead = geogig.command(RefParse.class).setName(remoteRef).call().get();
    assertEquals(newcommit.getId(), txRemoteHead.getObjectId());
    txRemoteHead = geogig.command(RefParse.class).setName(unchangedRemoteRef).call().get();
    assertEquals(headCommit.getId(), txRemoteHead.getObjectId());
}
Also used : Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) RemoteAddOp(org.locationtech.geogig.api.porcelain.RemoteAddOp) GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 68 with RevCommit

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

the class GeogigTransactionTest method testTransaction.

@Test
public void testTransaction() throws Exception {
    LinkedList<RevCommit> expectedMain = new LinkedList<RevCommit>();
    LinkedList<RevCommit> expectedTransaction = new LinkedList<RevCommit>();
    // make a commit
    insertAndAdd(points1);
    RevCommit commit = geogig.command(CommitOp.class).call();
    expectedMain.addFirst(commit);
    expectedTransaction.addFirst(commit);
    // start a transaction
    GeogigTransaction t = geogig.command(TransactionBegin.class).call();
    // perform a commit in the transaction
    insertAndAdd(t, points2);
    commit = t.command(CommitOp.class).call();
    expectedTransaction.addFirst(commit);
    // Verify that the base repository is unchanged
    Iterator<RevCommit> logs = geogig.command(LogOp.class).call();
    List<RevCommit> logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedMain, logged);
    // Verify that the transaction has the commit
    logs = t.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedTransaction, logged);
    // Commit the transaction
    geogig.command(TransactionEnd.class).setTransaction(t).setRebase(true).call();
    // Verify that the base repository has the changes from the transaction
    logs = geogig.command(LogOp.class).call();
    logged = new ArrayList<RevCommit>();
    for (; logs.hasNext(); ) {
        logged.add(logs.next());
    }
    assertEquals(expectedTransaction, logged);
}
Also used : GeogigTransaction(org.locationtech.geogig.api.GeogigTransaction) TransactionBegin(org.locationtech.geogig.api.plumbing.TransactionBegin) LogOp(org.locationtech.geogig.api.porcelain.LogOp) ArrayList(java.util.ArrayList) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) LinkedList(java.util.LinkedList) RevCommit(org.locationtech.geogig.api.RevCommit) TransactionEnd(org.locationtech.geogig.api.plumbing.TransactionEnd) Test(org.junit.Test)

Example 69 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 70 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)

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