Attach and detach a sub-tree (with tests)