Fix for when dulwich-managed repos get in bad state

This commit logs an error and deletes the master cachedir if the repo
cachedir gets into a bad state.