@Test public void testAmend() throws Exception { final ObjectId id = insertAndAdd(points1); final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call(); { assertCommit(commit1, null, null, null); assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId()); assertNotNull(repo.objectDatabase().get(id)); } final ObjectId id2 = insertAndAdd(points2); final RevCommit commit2 = geogig.command(CommitOp.class).setAmend(true).call(); { assertCommit(commit2, null, "groldan", "Message"); Optional<RevFeature> p2 = geogig.command(RevObjectParse.class) .setRefSpec("HEAD:" + appendChild(pointsName, idP2)).call(RevFeature.class); assertTrue(p2.isPresent()); assertEquals(id2, p2.get().getId()); Optional<RevFeature> p1 = geogig.command(RevObjectParse.class) .setRefSpec("HEAD:" + appendChild(pointsName, idP1)).call(RevFeature.class); assertTrue(p1.isPresent()); assertEquals(id, p1.get().getId()); } Iterator<RevCommit> log = geogig.command(LogOp.class).call(); assertTrue(log.hasNext()); log.next(); assertFalse(log.hasNext()); }
@Test public void testCommitUsingCommit() throws Exception { insertAndAdd(points1); final RevCommit commit = geogig.command(CommitOp.class) .setCommitter("anothercommitter", "anothercommitter@boundlessgeo.com").call(); insertAndAdd(points2); RevCommit commit2 = geogig.command(CommitOp.class).setCommit(commit).call(); assertEquals(commit.getMessage(), commit2.getMessage()); assertEquals(commit.getAuthor(), commit2.getAuthor()); assertNotSame(commit.getCommitter(), commit2.getCommitter()); }
@Test public void testCannotAmend() throws Exception { insertAndAdd(points1); try { geogig.command(CommitOp.class).setAmend(true).call(); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue(true); } }
private void assertCommit(RevCommit commit, @Nullable ObjectId parentId, String author, String message) { assertNotNull(commit); assertEquals(parentId == null ? 0 : 1, commit.getParentIds().size()); assertEquals(parentId, commit.parentN(0).orNull()); assertNotNull(commit.getTreeId()); assertNotNull(commit.getId()); if (author != null) { assertEquals(author, commit.getAuthor().getName().get()); } if (message != null) { assertEquals(message, commit.getMessage()); } assertNotNull(repo.getTree(commit.getTreeId())); assertEquals(commit.getId(), getRepository().getRef(Ref.HEAD).get().getObjectId()); }
@Test public void testEmptyCommit() throws Exception { 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); }
@Test public void testAmendNoChanges() throws Exception { final ObjectId id = insertAndAdd(points1); final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call(); { assertCommit(commit1, null, null, null); assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId()); assertNotNull(repo.objectDatabase().get(id)); } exception.expect(IllegalArgumentException.class); exception.expectMessage( "You must specify a new commit message, timestamp, or commit to reuse when amending a commit with no changes."); geogig.command(CommitOp.class).setAmend(true).call(); }
@Test public void testCommitAddsFeatureTypeToObjectDatabase() throws Exception { insertAndAdd(points1); ObjectId id = RevFeatureTypeBuilder.build(pointsType).getId(); geogig.command(AddOp.class).addPattern(".").call(); RevCommit commit = geogig.command(CommitOp.class).call(); assertNotNull(commit); RevFeatureType type = geogig.getRepository().objectDatabase().getFeatureType(id); assertEquals(id, type.getId()); }
@Test public void testCommitWithExplicitNullAuthorEmail() throws Exception { CommitOp commitCommand = geogig.command(CommitOp.class); commitCommand.setAuthor("John Doe", null); commitCommand.setAllowEmpty(true); RevCommit commit = commitCommand.call(); assertFalse(commit.getAuthor().getEmail().isPresent()); assertEquals("groldan", commit.getCommitter().getName().get()); assertEquals("groldan@boundlessgeo.com", commit.getCommitter().getEmail().get()); assertEquals("John Doe", commit.getAuthor().getName().get()); }
@Test public void testCommitWithDeletedTree() throws Exception { insertAndAdd(points1, points2); insertAndAdd(lines1, lines2); final RevCommit commit1 = geogig.command(CommitOp.class).call(); final RevTree tree1 = geogig.command(RevObjectParse.class).setObjectId(commit1.getTreeId()) .call(RevTree.class).get(); assertEquals(2, tree1.trees().size()); WorkingTree workingTree = geogig.getRepository().workingTree(); workingTree.delete(pointsName); geogig.command(AddOp.class).call(); final RevCommit commit2 = geogig.command(CommitOp.class).call(); RevTree tree2 = geogig.command(RevObjectParse.class).setObjectId(commit2.getTreeId()) .call(RevTree.class).get(); assertEquals(1, tree2.trees().size()); }
@Test public void testCommitEmptyTreeOnEmptyRepo() throws Exception { WorkingTree workingTree = geogig.getRepository().workingTree(); final String emptyTreeName = "emptyTree"; workingTree.createTypeTree(emptyTreeName, pointsType); geogig.command(AddOp.class).addPattern(emptyTreeName).call(); CommitOp commitCommand = geogig.command(CommitOp.class); RevCommit commit = commitCommand.call(); assertNotNull(commit); RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()) .call(RevTree.class).get(); Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName) .setParent(head).call(); assertTrue(ref.isPresent()); }
@Test public void testExplicitTimeStamp() throws Exception { CommitOp commitCommand = geogig.command(CommitOp.class); commitCommand.setAuthorTimestamp(1000L); commitCommand.setAuthorTimeZoneOffset(-3); commitCommand.setCommitterTimestamp(2000L); commitCommand.setCommitterTimeZoneOffset(+4); commitCommand.setAllowEmpty(true); RevCommit commit = commitCommand.call(); assertEquals(1000L, commit.getAuthor().getTimestamp()); assertEquals(-3, commit.getAuthor().getTimeZoneOffset()); assertEquals(2000L, commit.getCommitter().getTimestamp()); assertEquals(+4, commit.getCommitter().getTimeZoneOffset()); }
@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); 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()); verify(listener1, times(1)).isCanceled(); verify(listener2, times(2)).isCanceled(); verify(listener3, times(3)).isCanceled(); }
@Test public void testAmendNoChanges() throws Exception { final ObjectId id = insertAndAdd(points1); final RevCommit commit1 = geogig.command(CommitOp.class).setMessage("Message").call(); { assertCommit(commit1, null, null, null); assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId()); assertNotNull(repo.objectDatabase().get(id)); } exception.expect(IllegalArgumentException.class); exception.expectMessage( "You must specify a new commit message, timestamp, or commit to reuse when amending a commit with no changes."); geogig.command(CommitOp.class).setAmend(true).call(); }
@Test public void testEmptyCommit() throws Exception { 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); }
@Test public void testCommitAddsFeatureTypeToObjectDatabase() throws Exception { insertAndAdd(points1); ObjectId id = RevFeatureType.builder().type(pointsType).build().getId(); geogig.command(AddOp.class).addPattern(".").call(); RevCommit commit = geogig.command(CommitOp.class).call(); assertNotNull(commit); RevFeatureType type = geogig.getRepository().objectDatabase().getFeatureType(id); assertEquals(id, type.getId()); }
private void assertCommit(RevCommit commit, @Nullable ObjectId parentId, String author, String message) { assertNotNull(commit); assertEquals(parentId == null ? 0 : 1, commit.getParentIds().size()); assertEquals(parentId, commit.parentN(0).orNull()); assertNotNull(commit.getTreeId()); assertNotNull(commit.getId()); if (author != null) { assertEquals(author, commit.getAuthor().getName().get()); } if (message != null) { assertEquals(message, commit.getMessage()); } assertNotNull(repo.getTree(commit.getTreeId())); assertEquals(commit.getId(), getRepository().getRef(Ref.HEAD).get().getObjectId()); }
@Test public void testCommitWithExplicitNullAuthorEmail() throws Exception { CommitOp commitCommand = geogig.command(CommitOp.class); commitCommand.setAuthor("John Doe", null); commitCommand.setAllowEmpty(true); RevCommit commit = commitCommand.call(); assertFalse(commit.getAuthor().getEmail().isPresent()); assertEquals("groldan", commit.getCommitter().getName().get()); assertEquals("groldan@boundlessgeo.com", commit.getCommitter().getEmail().get()); assertEquals("John Doe", commit.getAuthor().getName().get()); }
@Test public void testCommitWithDeletedTree() throws Exception { insertAndAdd(points1, points2); insertAndAdd(lines1, lines2); final RevCommit commit1 = geogig.command(CommitOp.class).call(); final RevTree tree1 = geogig.command(RevObjectParse.class).setObjectId(commit1.getTreeId()) .call(RevTree.class).get(); assertEquals(2, tree1.trees().size()); WorkingTree workingTree = geogig.getRepository().workingTree(); workingTree.delete(pointsName); geogig.command(AddOp.class).call(); final RevCommit commit2 = geogig.command(CommitOp.class).call(); RevTree tree2 = geogig.command(RevObjectParse.class).setObjectId(commit2.getTreeId()) .call(RevTree.class).get(); assertEquals(1, tree2.trees().size()); }
@Test public void testCommitEmptyTreeOnEmptyRepo() throws Exception { WorkingTree workingTree = geogig.getRepository().workingTree(); final String emptyTreeName = "emptyTree"; workingTree.createTypeTree(emptyTreeName, pointsType); geogig.command(AddOp.class).addPattern(emptyTreeName).call(); CommitOp commitCommand = geogig.command(CommitOp.class); RevCommit commit = commitCommand.call(); assertNotNull(commit); RevTree head = geogig.command(RevObjectParse.class).setObjectId(commit.getTreeId()) .call(RevTree.class).get(); Optional<NodeRef> ref = geogig.command(FindTreeChild.class).setChildPath(emptyTreeName) .setParent(head).call(); assertTrue(ref.isPresent()); }
@Test public void testExplicitTimeStamp() throws Exception { CommitOp commitCommand = geogig.command(CommitOp.class); commitCommand.setAuthorTimestamp(1000L); commitCommand.setAuthorTimeZoneOffset(-3); commitCommand.setCommitterTimestamp(2000L); commitCommand.setCommitterTimeZoneOffset(+4); commitCommand.setAllowEmpty(true); RevCommit commit = commitCommand.call(); assertEquals(1000L, commit.getAuthor().getTimestamp()); assertEquals(-3, commit.getAuthor().getTimeZoneOffset()); assertEquals(2000L, commit.getCommitter().getTimestamp()); assertEquals(+4, commit.getCommitter().getTimeZoneOffset()); }