@Ignore @Test public void testUnexistentPathRemoval() throws Exception { populate(false, points1, points2, points3); try { geogig.command(RemoveOp.class).addPathToRemove("wrong/wrong.1").call(); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue(true); } }
/** * Runs the command and builds the appropriate response. * * @param context - the context to use for this command * * @throws CommandSpecException */ @Override protected void runInternal(CommandContext context) { final Context geogig = this.getRepositoryContext(context); NodeRef.checkValidPath(path); RemoveOp command = geogig.command(RemoveOp.class).setRecursive(recursive); command.addPathToRemove(path).call(); context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeElement("Deleted", path); out.finish(); } }); }
@Test public void testTruncateAndRecursivePrecondition() { exception.expect(IllegalArgumentException.class); exception.expectMessage("recursive and truncate arguments are mutually exclusive"); geogig.command(RemoveOp.class).addPathToRemove("tree").setRecursive(true).setTruncate(true) .call(); }
final WorkingTree workingTree = workingTree(); final Map<String, NodeRef> deleteTrees = getDeleteTrees(initialWorkTree); final List<String> deleteFeatures = filterFeatures(deleteTrees.keySet()); final ProgressListener listener = getProgressListener(); Optional<ObjectId> headTree = command(ResolveTreeish.class).setTreeish(Ref.HEAD).call(); ObjectId stageTree = stagingArea().getTree().getId(); final boolean nothingElseStaged = headTree.isPresent() && headTree.get().equals(stageTree); if (nothingElseStaged) { stagingArea().updateStageHead(finalWorkTree.getId()); } else { stageDeletes(deleteTrees.values().iterator(), deleteFeatures.iterator()); getProgressListener().setDescription("Computing result count..."); List<String> paths = new ArrayList<String>(deleteTrees.keySet()); paths.addAll(deleteFeatures); final DiffObjectCount stageCount = command(DiffCount.class)
@Override public void runInternal(GeogigCLI cli) throws IOException { Console console = cli.getConsole(); // check that there is something to remove if (pathsToRemove.isEmpty()) { printUsage(cli); throw new CommandFailedException(); } /* Perform the remove operation */ RemoveOp op = cli.getGeogig().command(RemoveOp.class).setRecursive(recursive) .setTruncate(truncate); for (String pathToRemove : pathsToRemove) { op.addPathToRemove(pathToRemove); } DiffObjectCount result; try { result = op.setProgressListener(cli.getProgressListener()).call(); } catch (IllegalArgumentException e) { throw new InvalidParameterException(e.getMessage()); } /* And inform about it */ console.println(String.format("Deleted %,d feature(s)", result.getFeaturesRemoved())); if (result.getTreesRemoved() > 0) { console.println(String.format("Deleted %,d trees", result.getTreesRemoved())); } if (result.getFeaturesRemoved() == 0 && result.getTreesRemoved() == 0) { throw new CommandFailedException(); } }
@Test public void testTruncate() throws Exception { insert(points1, points2, points3); insert(lines1, lines2, lines3); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(linesName) .setTruncate(true).call(); assertEquals(0, result.getTreesRemoved()); assertEquals(1, result.getTreesChanged()); assertEquals(3, result.getFeaturesRemoved()); } }
@Test public void testPathsPrecondition() { exception.expect(IllegalArgumentException.class); exception.expectMessage("No paths to remove were indicated"); geogig.command(RemoveOp.class).call(); }
private Map<String, NodeRef> getDeleteTrees(RevTree workTree) { Iterator<NodeRef> childTrees = command(LsTreeOp.class) .setStrategy(Strategy.DEPTHFIRST_ONLY_TREES) .setReference(workTree.getId().toString()).call(); ImmutableMap<String, NodeRef> treesByPath = Maps.uniqueIndex(childTrees, (ref) -> ref.path()); Set<String> requestedTrees = Sets.intersection(treesByPath.keySet(), new HashSet<>(pathsToRemove)); Predicate<String> keyPredicate = Predicates.in(requestedTrees); Map<String, NodeRef> requestedTreesMap = Maps.filterKeys(treesByPath, keyPredicate); return requestedTreesMap; }
@Override public void runInternal(GeogigCLI cli) throws IOException { Console console = cli.getConsole(); // check that there is something to remove if (pathsToRemove.isEmpty()) { printUsage(cli); throw new CommandFailedException(); } /* Perform the remove operation */ RemoveOp op = cli.getGeogig().command(RemoveOp.class).setRecursive(recursive) .setTruncate(truncate); for (String pathToRemove : pathsToRemove) { op.addPathToRemove(pathToRemove); } DiffObjectCount result; try { result = op.setProgressListener(cli.getProgressListener()).call(); } catch (IllegalArgumentException e) { throw new InvalidParameterException(e.getMessage()); } /* And inform about it */ console.println(String.format("Deleted %,d feature(s)", result.getFeaturesRemoved())); if (result.getTreesRemoved() > 0) { console.println(String.format("Deleted %,d trees", result.getTreesRemoved())); } if (result.getFeaturesRemoved() == 0 && result.getTreesRemoved() == 0) { throw new CommandFailedException(); } }
@Test public void testTruncate() throws Exception { insert(points1, points2, points3); insert(lines1, lines2, lines3); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(linesName) .setTruncate(true).call(); assertEquals(0, result.getTreesRemoved()); assertEquals(1, result.getTreesChanged()); assertEquals(3, result.getFeaturesRemoved()); } }
final WorkingTree workingTree = workingTree(); final Map<String, NodeRef> deleteTrees = getDeleteTrees(initialWorkTree); final List<String> deleteFeatures = filterFeatures(deleteTrees.keySet()); final ProgressListener listener = getProgressListener(); Optional<ObjectId> headTree = command(ResolveTreeish.class).setTreeish(Ref.HEAD).call(); ObjectId stageTree = stagingArea().getTree().getId(); final boolean nothingElseStaged = headTree.isPresent() && headTree.get().equals(stageTree); if (nothingElseStaged) { stagingArea().updateStageHead(finalWorkTree.getId()); } else { stageDeletes(deleteTrees.values().iterator(), deleteFeatures.iterator()); getProgressListener().setDescription("Computing result count..."); List<String> paths = new ArrayList<String>(deleteTrees.keySet()); paths.addAll(deleteFeatures); final DiffObjectCount stageCount = command(DiffCount.class)
@Test public void testPathsPrecondition() { exception.expect(IllegalArgumentException.class); exception.expectMessage("No paths to remove were indicated"); geogig.command(RemoveOp.class).call(); }
private Map<String, NodeRef> getDeleteTrees(RevTree workTree) { Iterator<NodeRef> childTrees = command(LsTreeOp.class) .setStrategy(Strategy.DEPTHFIRST_ONLY_TREES) .setReference(workTree.getId().toString()).call(); //NodeRef::path, but friendly for Fortify Function<NodeRef, String> fn_path = new Function<NodeRef, String>() { @Override public String apply(NodeRef noderef) { return noderef.path(); }}; ImmutableMap<String, NodeRef> treesByPath = Maps.uniqueIndex(childTrees, fn_path); Set<String> requestedTrees = Sets.intersection(treesByPath.keySet(), new HashSet<>(pathsToRemove)); Predicate<String> keyPredicate = Predicates.in(requestedTrees); Map<String, NodeRef> requestedTreesMap = Maps.filterKeys(treesByPath, keyPredicate); return requestedTreesMap; }
@Ignore @Test public void testUnexistentPathRemoval() throws Exception { populate(false, points1, points2, points3); try { geogig.command(RemoveOp.class).addPathToRemove("wrong/wrong.1").call(); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue(true); } }
command(RemoveOp.class).setRecursive(true).addPathToRemove(path).call(); NodeRef foundChild = command(FindTreeChild.class).setParent(currentWorkHead) .setChildPath(path).call().orNull();
@Test public void testTruncateAndRecursivePrecondition() { exception.expect(IllegalArgumentException.class); exception.expectMessage("recursive and truncate arguments are mutually exclusive"); geogig.command(RemoveOp.class).addPathToRemove("tree").setRecursive(true).setTruncate(true) .call(); }
@Override public void runInternal(GeogigCLI cli) throws IOException { Console console = cli.getConsole(); // check that there is something to remove if (pathsToRemove.isEmpty()) { printUsage(cli); throw new CommandFailedException(); } /* Perform the remove operation */ RemoveOp op = cli.getGeogig().command(RemoveOp.class).setRecursive(recursive) .setTruncate(truncate); for (String pathToRemove : pathsToRemove) { op.addPathToRemove(pathToRemove); } DiffObjectCount result; try { result = op.setProgressListener(cli.getProgressListener()).call(); } catch (IllegalArgumentException e) { throw new InvalidParameterException(e.getMessage()); } /* And inform about it */ console.println(String.format("Deleted %,d feature(s)", result.getFeaturesRemoved())); if (result.getTreesRemoved() > 0) { console.println(String.format("Deleted %,d trees", result.getTreesRemoved())); } if (result.getFeaturesRemoved() == 0 && result.getTreesRemoved() == 0) { throw new CommandFailedException(); } }
@Test public void testSingleFeatureRemoval() throws Exception { populate(false, points1, points2, points3); String featureId = points1.getIdentifier().getID(); String path = NodeRef.appendChild(pointsName, featureId); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path).call(); assertEquals(1, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path).call(); assertFalse(id.isPresent()); }
command(RemoveOp.class).setRecursive(true).addPathToRemove(path).call(); NodeRef foundChild = command(FindTreeChild.class).setParent(currentWorkHead) .setChildPath(path).call().orNull();
@Test public void testTruncateOrRecursivePrecondition() throws Exception { insertAndAdd(points1); exception.expect(IllegalArgumentException.class); exception.expectMessage( "Cannot remove tree " + pointsName + " if recursive or truncate is not specified"); geogig.command(RemoveOp.class).addPathToRemove(pointsName).setRecursive(false) .setTruncate(false).call(); }