MDLSITE-3680 fix integration.git detection

Previously our detection of the ancestor was not always finding the
correct ancestor. By using git merge-base be find the point which git
will use for a 3 way merge i.e. the point it forked.
MDLSITE-3680 improve error handling

When I was testing MDLSITE-3680 I drove myself crazy trying to work out
where a problem was occuring - it turned out that the

git checkout MOODLE_27_STABLE && git reset (etc etc) was failing, then
it was continuing to process based on the existing merge branch, from
the previous run. This makes the script die when one of these operations
fail.
Merge pull request #37 from danpoltawski/MDLSITE-3680

MDLSITE-3680 fix detection of merge point