Issue 606

Fixes #606 includes unit tests. Needs some manual e2e verification or some extra functional automated tests. I've only tested in in cloning an empty repository.