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