Miscellaneous repo/changeset fixes

* better git statuses handling
* refactoring and cleanup to make it testable
You do this in exactly one function in this code, we should put this there, not for the whole file.