Fixes for a standalone index

An `Index` can exist on its own, so we need to make sure it works even without an associated repository. `read_tree()` would segfault for an index which was created through its constructor. In those cases, we need the object directly, as we don't know where to look it up.