Use checked-out branch as default branch.

Previously assumed 'master' was the default branch, when master may not
exist at all.

(Note that the test case has not been successfully tested, due to a weird config issue on the machine I did this on. Someone should verify that it works before merging it.)