Make GitHub post-commit more reliable with "main" branch.
Review Request #11251 — Created Oct. 27, 2020 and submitted — Latest diff uploaded
Now that Git supports it, more and more people are choosing to name
their mainline branch something other than "master". While before we
were relatively confident that one of the branches fetched would have
this name, that's no longer the case. This is particularly bad for the
case where there's only one branch, because if none of the branches were
marked as default, the frontend would never fetch the commits.This change updates the GitHub
get_branches
method to make sure that
there's always a default branch set. If a branch is found named
"master", we'll use that one, then it will try "main", and finally if
neither is chosen, we'll just mark the first branch as the default.At the moment GitHub doesn't have a way for us to know what's the
default (there's a user setting for when new repositories are created,
but that doesn't tell us anything about existing repositories,
especially those that are part of organizations rather than personal
repos). Hopefully they'll add this to their API at some point and we'll
be able to simplify this then.
Created a new repository with only one branch, named "main". Saw that I
could open the "New Review Request" page and that the main branch was
selected and commits were properly loaded.