/** * @return */ RevTree getTypeTree() { String refSpec = getRootRef() + ":" + getTypeTreePath(); Context commandLocator = getCommandLocator(); Optional<RevTree> ref = commandLocator.command(RevObjectParse.class).setRefSpec(refSpec) .call(RevTree.class); Preconditions.checkState(ref.isPresent(), "Ref %s not found on working tree", refSpec); return ref.get(); }
/** * @return */ RevTree getTypeTree() { String refSpec = getRootRef() + ":" + getTypeTreePath(); Context commandLocator = getCommandLocator(); Optional<RevTree> ref = commandLocator.command(RevObjectParse.class).setRefSpec(refSpec) .call(RevTree.class); Preconditions.checkState(ref.isPresent(), "Ref %s not found on working tree", refSpec); return ref.get(); }
@Override public void runInternal(GeogigCLI cli) throws IOException { checkParameter(commits.size() == 2, "Two commit references must be provided"); Console console = cli.getConsole(); GeoGIG geogig = cli.getGeogig(); Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)) .call(); checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object."); checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit"); Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)) .call(); checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object."); checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit"); Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class) .setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call(); checkParameter(ancestor.isPresent(), "No common ancestor was found."); console.print(ancestor.get().toString()); }
/** * Executes the tag removal operation. * * @return the tag to remove * */ @Override protected RevTag _call() throws RuntimeException { String fullPath = Ref.TAGS_PREFIX + name; Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call(); Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name); Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag"); UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true) .setReason("Delete tag " + name); Optional<Ref> tagRef = updateRef.call(); checkState(tagRef.isPresent()); return (RevTag) revTag.get(); }
/** * Executes the tag removal operation. * * @return the tag to remove * */ @Override protected RevTag _call() throws RuntimeException { String fullPath = Ref.TAGS_PREFIX + name; Optional<RevObject> revTag = command(RevObjectParse.class).setRefSpec(fullPath).call(); Preconditions.checkArgument(revTag.isPresent(), "Wrong tag name: " + name); Preconditions.checkArgument(revTag.get().getType().equals(RevObject.TYPE.TAG), name + " does not resolve to a tag"); UpdateRef updateRef = command(UpdateRef.class).setName(fullPath).setDelete(true) .setReason("Delete tag " + name); Optional<Ref> tagRef = updateRef.call(); checkState(tagRef.isPresent()); return (RevTag) revTag.get(); }
private Optional<Ref> resolveRef(@Nullable String head, Context repo) { Ref ref = null; if (head != null) { ref = repo.command(RefParse.class).setName(head).call().orNull(); if (null == ref) { RevObject root = repo.command(RevObjectParse.class).setRefSpec(head).call() .orNull(); if (null != root) { ref = new Ref(root.getType().toString(), root.getId()); } } } return Optional.ofNullable(ref); }
private Optional<RevFeature> getFeatureFromRefSpec() { Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref) .call(RevObject.class); if (!revObject.isPresent()) { // let's try to see if it is a feature in the working tree NodeRef.checkValidPath(ref); Optional<NodeRef> elementRef = command(FindTreeChild.class) .setParent(workingTree().getTree()).setChildPath(ref).call(); Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref); ObjectId id = elementRef.get().getObjectId(); revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class); } if (revObject.isPresent()) { Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref); return Optional.of(RevFeature.class.cast(revObject.get())); } else { return Optional.absent(); } }
private Optional<RevFeature> getFeatureFromRefSpec() { Optional<RevObject> revObject = command(RevObjectParse.class).setRefSpec(ref) .call(RevObject.class); if (!revObject.isPresent()) { // let's try to see if it is a feature in the working tree NodeRef.checkValidPath(ref); Optional<NodeRef> elementRef = command(FindTreeChild.class) .setParent(workingTree().getTree()).setChildPath(ref).call(); Preconditions.checkArgument(elementRef.isPresent(), "Invalid reference: %s", ref); ObjectId id = elementRef.get().getObjectId(); revObject = command(RevObjectParse.class).setObjectId(id).call(RevObject.class); } if (revObject.isPresent()) { Preconditions.checkArgument(TYPE.FEATURE.equals(revObject.get().getType()), "%s does not resolve to a feature", ref); return Optional.of(RevFeature.class.cast(revObject.get())); } else { return Optional.absent(); } }
/** * @return the {@link ObjectId} of the root tree */ @Override public ObjectId getRootTreeId() { // find the root tree ObjectId commitId = command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); if (commitId.isNull()) { return commitId; } RevCommit commit = command(RevObjectParse.class).setRefSpec(commitId.toString()) .call(RevCommit.class).get(); ObjectId treeId = commit.getTreeId(); return treeId; }
/** * @return the {@link ObjectId} of the root tree */ @Override public ObjectId getRootTreeId() { // find the root tree ObjectId commitId = command(RevParse.class).setRefSpec(Ref.HEAD).call().get(); if (commitId.isNull()) { return commitId; } RevCommit commit = command(RevObjectParse.class).setRefSpec(commitId.toString()) .call(RevCommit.class).get(); ObjectId treeId = commit.getTreeId(); return treeId; }
@Test public void testImportWithFid() throws Exception { ImportOp importOp = geogig.command(ImportOp.class); importOp.setDataStore(TestHelper.createTestFactory().createDataStore(ImmutableMap.of())); importOp.setTable("table3"); importOp.setDestinationPath("table3"); importOp.setFidAttribute("number"); importOp.call(); Optional<RevFeature> feature = geogig.command(RevObjectParse.class) .setRefSpec("WORK_HEAD:table3/1000").call(RevFeature.class); assertTrue(feature.isPresent()); }
@Test public void testImportWithFid() throws Exception { ImportOp importOp = geogig.command(ImportOp.class); importOp.setDataStore(TestHelper.createTestFactory().createDataStore(ImmutableMap.of())); importOp.setTable("table3"); importOp.setDestinationPath("table3"); importOp.setFidAttribute("number"); importOp.call(); Optional<RevFeature> feature = geogig.command(RevObjectParse.class) .setRefSpec("WORK_HEAD:table3/1000").call(RevFeature.class); assertTrue(feature.isPresent()); }
@Test public void testImportTableWithNoFeatures() throws Exception { ImportOp importOp = geogig.command(ImportOp.class); importOp.setDataStore(TestHelper.createTestFactory().createDataStore(ImmutableMap.of())); importOp.setAll(false); importOp.setTable("table4"); importOp.call(); geogig.command(AddOp.class).call(); Optional<RevObject> ft = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table4") .call(); assertTrue(ft.isPresent()); }
@Test public void testTagCreation() throws Exception { insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); RevTag tag = geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName("Tag1") .call(); Optional<RevTag> databaseTag = geogig.command(RevObjectParse.class).setRefSpec("Tag1") .call(RevTag.class); assertTrue(databaseTag.isPresent()); assertEquals(tag, databaseTag.get()); }
@Test public void testTagCreation() throws Exception { insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); RevTag tag = geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName("Tag1") .call(); Optional<RevTag> databaseTag = geogig.command(RevObjectParse.class).setRefSpec("Tag1") .call(RevTag.class); assertTrue(databaseTag.isPresent()); assertEquals(tag, databaseTag.get()); }
@Test public void testImportTableWithNoFeatures() throws Exception { ImportOp importOp = geogig.command(ImportOp.class); importOp.setDataStore(TestHelper.createTestFactory().createDataStore(ImmutableMap.of())); importOp.setAll(false); importOp.setTable("table4"); importOp.call(); geogig.command(AddOp.class).call(); Optional<RevObject> ft = geogig.command(RevObjectParse.class).setRefSpec("WORK_HEAD:table4") .call(); assertTrue(ft.isPresent()); }
@Test public void testCannotAdaptFeatureTypeIfCRSChanges() throws Exception { ImportOp importOp = geogig.command(ImportOp.class); importOp.setDataStore(TestHelper.createTestFactory().createDataStore(ImmutableMap.of())); importOp.setTable("GeoJsonLikeTable"); importOp.setDestinationPath("table"); importOp.call(); Optional<RevFeature> feature = geogig.command(RevObjectParse.class) .setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class); assertTrue(feature.isPresent()); importOp.setTable("GeoJsonLikeTable2"); try { importOp.call(); fail(); } catch (GeoToolsOpException e) { assertEquals(GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE, e.statusCode); } }
@Test public void testCannotAdaptFeatureTypeIfCRSChanges() throws Exception { ImportOp importOp = geogig.command(ImportOp.class); importOp.setDataStore(TestHelper.createTestFactory().createDataStore(ImmutableMap.of())); importOp.setTable("GeoJsonLikeTable"); importOp.setDestinationPath("table"); importOp.call(); Optional<RevFeature> feature = geogig.command(RevObjectParse.class) .setRefSpec("WORK_HEAD:table/feature1").call(RevFeature.class); assertTrue(feature.isPresent()); importOp.setTable("GeoJsonLikeTable2"); try { importOp.call(); fail(); } catch (GeoToolsOpException e) { assertEquals(GeoToolsOpException.StatusCode.INCOMPATIBLE_FEATURE_TYPE, e.statusCode); } }
@Test public void testTagRemoval() throws Exception { insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); RevTag tag = geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName("Tag1") .call(); Optional<RevTag> databaseTag = geogig.command(RevObjectParse.class).setRefSpec("Tag1") .call(RevTag.class); assertTrue(databaseTag.isPresent()); RevTag removedTag = geogig.command(TagRemoveOp.class).setName("Tag1").call(); assertEquals(tag, removedTag); Optional<ObjectId> databaseTagId = geogig.command(RevParse.class).setRefSpec("Tag1").call(); assertFalse(databaseTagId.isPresent()); }
@Test public void testTagRemoval() throws Exception { insertAndAdd(points1); RevCommit commit = geogig.command(CommitOp.class).call(); RevTag tag = geogig.command(TagCreateOp.class).setCommitId(commit.getId()).setName("Tag1") .call(); Optional<RevTag> databaseTag = geogig.command(RevObjectParse.class).setRefSpec("Tag1") .call(RevTag.class); assertTrue(databaseTag.isPresent()); RevTag removedTag = geogig.command(TagRemoveOp.class).setName("Tag1").call(); assertEquals(tag, removedTag); Optional<ObjectId> databaseTagId = geogig.command(RevParse.class).setRefSpec("Tag1").call(); assertFalse(databaseTagId.isPresent()); }