Compare against repositories when comparing branches.

As we weren't caring about which repository this object belonged to, this could result in a crash within libgit2.

One thing I'm not sure about here is whether we should care that it is the exact same repository object, as opposed to whether it's just the same repository on disk.

/cc @arrbee