MDLSITE-3680 fix detection of merge point 

There are two commits:

603e6d - is fixing the bug. Our 'ancestor' detection was not working correctly (at least not how I expected it to work).

afefa43 - is just about improving the error handling, because when I was testing on my local repo the branch 'MOODLE_27_STABLE' did not exist and so the git checkout was silently failing and then getting a completely unrelated commit for basecommit.