Fixed race condition when cloning repository

The index is dropped after the clone finished, then a new index is created (and loads its state from disk) when the folder is added to the workspace.
It means that we first need to flush the index to disk before the second index is created.

review: @gaurave @devoncarew