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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations