VCS_INFO_git_getbranch () { #{{{ local gitbranch gitdir=$1 local gitsymref='git symbolic-ref HEAD' if [[ -d "${gitdir}/rebase-apply" ]] \ || [[ -d "${gitdir}/rebase" ]] \ || [[ -d "${gitdir}/../.dotest" ]] \ || [[ -f "${gitdir}/MERGE_HEAD" ]] ; then gitbranch="$(${(z)gitsymref} 2> /dev/null)" [[ -z ${gitbranch} ]] && [[ -r ${gitdir}/rebase-apply/head-name ]] \ && gitbranch="$(< ${gitdir}/rebase-apply/head-name)" elif [[ -f "${gitdir}/rebase-merge/interactive" ]] \ || [[ -d "${gitdir}/rebase-merge" ]] ; then gitbranch="$(< ${gitdir}/rebase-merge/head-name)" elif [[ -f "${gitdir}/.dotest-merge/interactive" ]] \ || [[ -d "${gitdir}/.dotest-merge" ]] ; then gitbranch="$(< ${gitdir}/.dotest-merge/head-name)" else gitbranch="$(${(z)gitsymref} 2> /dev/null)" if [[ $? -ne 0 ]] ; then gitbranch="$(git describe --exact-match HEAD 2>/dev/null)" if [[ $? -ne 0 ]] ; then gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..." fi fi fi printf '%s' "${gitbranch##refs/heads/}" return 0 }