Fix error when getting the current branch but it is checked out to a commit

1. when a repo checkout to a existing branch, its HEAD file would be "ref: refs/heads/{branch name}"
2. when it is checkout to a commit, its HEAD file would be the commit hash, e.g. "d85f686d388e333abde2ac89020f2f127d9d7e9d"

This pull request handle the second scenario by returning an error indicating that the current branch is not a valid branch.