use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class Commit method run.
/**
* Runs the command and builds the appropriate response
*
* @param context - the context to use for this command
* @throws CommandSpecException
*/
@Override
public void run(CommandContext context) {
if (this.getTransactionId() == null) {
throw new CommandSpecException("No transaction was specified, commit requires a transaction to preserve the stability of the repository.");
}
final Context geogig = this.getCommandLocator(context);
RevCommit commit;
try {
commit = geogig.command(CommitOp.class).setAuthor(authorName.orNull(), authorEmail.orNull()).setMessage(message).setAllowEmpty(true).setAll(all).call();
assert commit != null;
} catch (NothingToCommitException noChanges) {
context.setResponseContent(CommandResponse.warning("Nothing to commit"));
commit = null;
} catch (IllegalStateException e) {
context.setResponseContent(CommandResponse.warning(e.getMessage()));
commit = null;
}
if (commit != null) {
final RevCommit commitToWrite = commit;
final ObjectId parentId = commit.parentN(0).or(ObjectId.NULL);
final Iterator<DiffEntry> diff = geogig.command(DiffOp.class).setOldVersion(parentId).setNewVersion(commit.getId()).call();
context.setResponseContent(new CommandResponse() {
@Override
public void write(ResponseWriter out) throws Exception {
out.start();
out.writeCommitResponse(commitToWrite, diff);
out.finish();
}
});
}
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class CommitOpTest method testInitialCommit.
@Test
public void testInitialCommit() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
ObjectId oid1 = insertAndAdd(points1);
ObjectId oid2 = insertAndAdd(points2);
geogig.command(AddOp.class).addPattern(".").call();
RevCommit commit = geogig.command(CommitOp.class).call();
assertNotNull(commit);
assertNotNull(commit.getParentIds());
assertEquals(0, commit.getParentIds().size());
assertFalse(commit.parentN(0).isPresent());
assertNotNull(commit.getId());
assertEquals("groldan", commit.getAuthor().getName().get());
assertEquals("groldan@boundlessgeo.com", commit.getAuthor().getEmail().get());
ObjectId treeId = commit.getTreeId();
assertNotNull(treeId);
RevTree root = repo.getTree(treeId);
assertNotNull(root);
Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
assertTrue(typeTreeId.isPresent());
RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
String featureId = points1.getIdentifier().getID();
String path = NodeRef.appendChild(pointsName, featureId);
Optional<Node> featureBlobId = repo.getTreeChild(root, path);
assertTrue(featureBlobId.isPresent());
assertEquals(oid1, featureBlobId.get().getObjectId());
featureId = points2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
assertEquals(oid2, featureBlobId.get().getObjectId());
ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
assertEquals(commit.getId(), commitId);
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class CommitOpTest method testEmptyCommit.
@Test
public void testEmptyCommit() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
CommitOp commitCommand = geogig.command(CommitOp.class);
RevCommit commit = commitCommand.setAllowEmpty(true).call();
assertNotNull(commit);
assertNotNull(commit.getParentIds());
assertEquals(0, commit.getParentIds().size());
assertFalse(commit.parentN(0).isPresent());
assertNotNull(commit.getId());
ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
assertEquals(commit.getId(), commitId);
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class CommitOpTest method testNoCommitterName.
@Test
public void testNoCommitterName() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
injector.configDatabase().remove("user.name");
CommitOp commitCommand = geogig.command(CommitOp.class);
exception.expect(IllegalStateException.class);
commitCommand.setAllowEmpty(true).call();
}
use of org.locationtech.geogig.api.porcelain.NothingToCommitException in project GeoGig by boundlessgeo.
the class CommitOpTest method testCommitWithAllOptionAndPaths.
@Test
public void testCommitWithAllOptionAndPaths() throws Exception {
try {
geogig.command(AddOp.class).addPattern(".").call();
geogig.command(CommitOp.class).call();
fail("expected NothingToCommitException");
} catch (NothingToCommitException e) {
assertTrue(true);
}
insertAndAdd(points1);
geogig.command(AddOp.class).addPattern(".").call();
RevCommit commit = geogig.command(CommitOp.class).call();
ObjectId oid = insertAndAdd(points1_modified);
insert(points2);
insert(lines1);
CommitOp commitCommand = geogig.command(CommitOp.class);
commit = commitCommand.setPathFilters(ImmutableList.of(pointsName)).setAll(true).call();
assertNotNull(commit);
assertNotNull(commit.getParentIds());
assertEquals(1, commit.getParentIds().size());
assertNotNull(commit.getId());
ObjectId treeId = commit.getTreeId();
assertNotNull(treeId);
RevTree root = repo.getTree(treeId);
assertNotNull(root);
Optional<Node> linesTreeId = repo.getTreeChild(root, linesName);
assertFalse(linesTreeId.isPresent());
Optional<Node> typeTreeId = repo.getTreeChild(root, pointsName);
assertTrue(typeTreeId.isPresent());
RevTree typeTree = repo.getTree(typeTreeId.get().getObjectId());
assertNotNull(typeTree);
String featureId = points1.getIdentifier().getID();
Optional<Node> featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertTrue(featureBlobId.isPresent());
assertEquals(oid, featureBlobId.get().getObjectId());
featureId = points2.getIdentifier().getID();
featureBlobId = repo.getTreeChild(root, NodeRef.appendChild(pointsName, featureId));
assertFalse(featureBlobId.isPresent());
ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get();
assertEquals(commit.getId(), commitId);
}
Aggregations