Search in sources :

Example 6 with NothingToCommitException

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();
            }
        });
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) ObjectId(org.locationtech.geogig.api.ObjectId) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) DiffOp(org.locationtech.geogig.api.porcelain.DiffOp) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevCommit(org.locationtech.geogig.api.RevCommit) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 7 with NothingToCommitException

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);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 8 with NothingToCommitException

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);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Example 9 with NothingToCommitException

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();
}
Also used : NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Test(org.junit.Test)

Example 10 with NothingToCommitException

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);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevParse(org.locationtech.geogig.api.plumbing.RevParse) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) Node(org.locationtech.geogig.api.Node) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit) Test(org.junit.Test)

Aggregations

NothingToCommitException (org.locationtech.geogig.api.porcelain.NothingToCommitException)15 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)10 Test (org.junit.Test)9 ObjectId (org.locationtech.geogig.api.ObjectId)8 RevCommit (org.locationtech.geogig.api.RevCommit)8 RevParse (org.locationtech.geogig.api.plumbing.RevParse)6 Node (org.locationtech.geogig.api.Node)5 RevTree (org.locationtech.geogig.api.RevTree)4 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3 DiffOp (org.locationtech.geogig.api.porcelain.DiffOp)3 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)3 ConsoleReader (jline.console.ConsoleReader)2 Ansi (org.fusesource.jansi.Ansi)2 Ref (org.locationtech.geogig.api.Ref)2 MergeOp (org.locationtech.geogig.api.porcelain.MergeOp)2 Optional (com.google.common.base.Optional)1 File (java.io.File)1 TimeoutException (java.util.concurrent.TimeoutException)1 Ignore (org.junit.Ignore)1