version.sh: Improve the handling of the branch name.

The branch name was cut when on no branch.