Fix for `discover_default_branch` returning `master` when it doesn't exist.

When more than 1 branch exists and neither are `master` and the `HEAD`
has not been updated to one of the existing branches, discover_default_branch
would return `master`.

This checks that `HEAD` exists before returning it.
 Merge branch 'fix/discover_default_branch' into 'master'

Fix for discover_default_branch

When more than 1 branch exists and neither are `master` and the `HEAD`
has not been updated to one of the existing branches, discover_default_branch
would return `master`.

This checks that `HEAD` exists before returning it.

This has been reported https://gitlab.com/gitlab-org/gitlab-ce/issues/108.
Version 5.7.0

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Additional fix for branch name detection

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>