Search in sources :

Example 6 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp 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 7 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp 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 8 with CommitOp

use of org.locationtech.geogig.api.porcelain.CommitOp 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)

Example 9 with CommitOp

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

the class CommitOpTest method testNoCommitterEmail.

@Test
public void testNoCommitterEmail() 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.email");
    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 CommitOp

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

the class CommitOpTest method testCancel.

@Test
public void testCancel() throws Exception {
    ProgressListener listener1 = mock(ProgressListener.class);
    when(listener1.isCanceled()).thenReturn(true);
    ProgressListener listener2 = mock(ProgressListener.class);
    when(listener2.isCanceled()).thenReturn(false, true);
    ProgressListener listener3 = mock(ProgressListener.class);
    when(listener3.isCanceled()).thenReturn(false, false, true);
    try {
        geogig.command(AddOp.class).addPattern(".").call();
        geogig.command(CommitOp.class).call();
        fail("expected NothingToCommitException");
    } catch (NothingToCommitException e) {
        assertTrue(true);
    }
    CommitOp commitCommand1 = geogig.command(CommitOp.class);
    commitCommand1.setProgressListener(listener1);
    assertNull(commitCommand1.setAllowEmpty(true).call());
    CommitOp commitCommand2 = geogig.command(CommitOp.class);
    commitCommand2.setProgressListener(listener2);
    assertNull(commitCommand2.setAllowEmpty(true).call());
    CommitOp commitCommand3 = geogig.command(CommitOp.class);
    commitCommand3.setProgressListener(listener3);
    assertNull(commitCommand3.setAllowEmpty(true).call());
}
Also used : ProgressListener(org.locationtech.geogig.api.ProgressListener) NothingToCommitException(org.locationtech.geogig.api.porcelain.NothingToCommitException) CommitOp(org.locationtech.geogig.api.porcelain.CommitOp) Test(org.junit.Test)

Aggregations

CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)12 Test (org.junit.Test)9 NothingToCommitException (org.locationtech.geogig.api.porcelain.NothingToCommitException)9 RevCommit (org.locationtech.geogig.api.RevCommit)8 ObjectId (org.locationtech.geogig.api.ObjectId)5 RevTree (org.locationtech.geogig.api.RevTree)5 RevParse (org.locationtech.geogig.api.plumbing.RevParse)4 Node (org.locationtech.geogig.api.Node)3 NodeRef (org.locationtech.geogig.api.NodeRef)3 ConsoleReader (jline.console.ConsoleReader)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)2 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)2 AddOp (org.locationtech.geogig.api.porcelain.AddOp)2 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)2 WorkingTree (org.locationtech.geogig.repository.WorkingTree)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1