@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); }
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); }
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 testCommitWithAllOption() throws Exception { insertAndAdd(points1); geogig.command(AddOp.class).addPattern(".").call(); RevCommit commit = geogig.command(CommitOp.class).call(); ObjectId oid = insertAndAdd(points1_modified); CommitOp commitCommand = geogig.command(CommitOp.class); commit = commitCommand.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> 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()); ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); assertEquals(commit.getId(), commitId); }
@Test public void testCommitWithAllOption() throws Exception { insertAndAdd(points1); geogig.command(AddOp.class).addPattern(".").call(); RevCommit commit = geogig.command(CommitOp.class).call(); ObjectId oid = insertAndAdd(points1_modified); CommitOp commitCommand = geogig.command(CommitOp.class); commit = commitCommand.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> 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()); ObjectId commitId = geogig.command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); assertEquals(commit.getId(), commitId); }
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()); assertNotNull(treeId); RevTree root = repo.getTree(treeId); assertNotNull(root); assertNotNull(typeTree);
@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 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 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 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 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 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 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()); }
@Test public void testAmendReUseCommit() 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 RevCommit commit2 = geogig.command(CommitOp.class).setAmend(true).setCommit(commit1) .call(); { assertCommit(commit2, null, "groldan", "Message"); Optional<RevFeature> p1 = geogig.command(RevObjectParse.class) .setRefSpec("HEAD:" + appendChild(pointsName, idP1)).call(RevFeature.class); assertTrue(p1.isPresent()); assertEquals(id, p1.get().getId()); assertEquals(commit1.getAuthor(), commit2.getAuthor()); assertEquals(commit1.getCommitter().getName(), commit2.getCommitter().getName()); assertEquals(commit1.getCommitter().getEmail(), commit2.getCommitter().getEmail()); assertEquals(commit1.getMessage(), commit2.getMessage()); assertEquals(commit1.getParentIds(), commit2.getParentIds()); assertEquals(commit1.getTreeId(), commit2.getTreeId()); } Iterator<RevCommit> log = geogig.command(LogOp.class).call(); assertTrue(log.hasNext()); log.next(); assertFalse(log.hasNext()); }
@Test public void testAmendCommitMessage() 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 RevCommit commit2 = geogig.command(CommitOp.class).setAmend(true) .setMessage("Updated Message").call(); { assertCommit(commit2, null, "groldan", "Updated Message"); Optional<RevFeature> p1 = geogig.command(RevObjectParse.class) .setRefSpec("HEAD:" + appendChild(pointsName, idP1)).call(RevFeature.class); assertTrue(p1.isPresent()); assertEquals(id, p1.get().getId()); assertEquals(commit1.getAuthor().getName(), commit2.getAuthor().getName()); assertEquals(commit1.getAuthor().getEmail(), commit2.getAuthor().getEmail()); assertEquals(commit1.getCommitter().getName(), commit2.getCommitter().getName()); assertEquals(commit1.getCommitter().getEmail(), commit2.getCommitter().getEmail()); assertEquals(commit1.getParentIds(), commit2.getParentIds()); assertEquals(commit1.getTreeId(), commit2.getTreeId()); } Iterator<RevCommit> log = geogig.command(LogOp.class).call(); assertTrue(log.hasNext()); log.next(); assertFalse(log.hasNext()); }
@Test public void testAmendCommitMessage() 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 RevCommit commit2 = geogig.command(CommitOp.class).setAmend(true) .setMessage("Updated Message").call(); { assertCommit(commit2, null, "groldan", "Updated Message"); Optional<RevFeature> p1 = geogig.command(RevObjectParse.class) .setRefSpec("HEAD:" + appendChild(pointsName, idP1)).call(RevFeature.class); assertTrue(p1.isPresent()); assertEquals(id, p1.get().getId()); assertEquals(commit1.getAuthor().getName(), commit2.getAuthor().getName()); assertEquals(commit1.getAuthor().getEmail(), commit2.getAuthor().getEmail()); assertEquals(commit1.getCommitter().getName(), commit2.getCommitter().getName()); assertEquals(commit1.getCommitter().getEmail(), commit2.getCommitter().getEmail()); assertEquals(commit1.getParentIds(), commit2.getParentIds()); assertEquals(commit1.getTreeId(), commit2.getTreeId()); } Iterator<RevCommit> log = geogig.command(LogOp.class).call(); assertTrue(log.hasNext()); log.next(); assertFalse(log.hasNext()); }
assertEquals(id, repo.getRootTreeChild(appendChild(pointsName, idP1)).get().getObjectId()); assertNotNull(repo.objectDatabase().get(id));