} else {
checkState(node.isPresent(), "pathspec '" + st
+ "' didn't match a feature in the tree");
if (node.get().getType() == TYPE.TREE) {
RevTreeBuilder treeBuilder = new RevTreeBuilder(stagingDatabase(),
workingTree().getTree());
treeBuilder.remove(st);
treeBuilder.put(node.get().getNode());
RevTree newRoot = treeBuilder.build();
stagingDatabase().put(newRoot);
workingTree().updateWorkHead(newRoot.getId());
} else {
ObjectId metadataId = ObjectId.NULL;
Optional<NodeRef> parentNode = command(FindTreeChild.class)
.setParent(workingTree().getTree())
.setChildPath(node.get().getParentPath()).setIndex(true).call();
RevTreeBuilder treeBuilder = null;
if (parentNode.isPresent()) {
metadataId = parentNode.get().getMetadataId();
Optional<RevTree> parsed = command(RevObjectParse.class).setObjectId(
parentNode.get().getNode().getObjectId()).call(RevTree.class);
checkState(parsed.isPresent(),
"Parent tree couldn't be found in the repository.");
treeBuilder = new RevTreeBuilder(stagingDatabase(), parsed.get());
treeBuilder.remove(node.get().getNode().getName());
} else {
treeBuilder = new RevTreeBuilder(stagingDatabase());
}
treeBuilder.put(node.get().getNode());
ObjectId newTreeId = command(WriteBack.class)
.setAncestor(
workingTree().getTree().builder(stagingDatabase()))
.setChildPath(node.get().getParentPath()).setToIndex(true)
.setTree(treeBuilder.build()).setMetadataId(metadataId).call();
workingTree().updateWorkHead(newTreeId);
}
}
}