diff options
Diffstat (limited to 'zshfunc/vcs-info/VCS_INFO_git_getbranch')
-rw-r--r-- | zshfunc/vcs-info/VCS_INFO_git_getbranch | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/zshfunc/vcs-info/VCS_INFO_git_getbranch b/zshfunc/vcs-info/VCS_INFO_git_getbranch new file mode 100644 index 0000000..03c5fa5 --- /dev/null +++ b/zshfunc/vcs-info/VCS_INFO_git_getbranch @@ -0,0 +1,35 @@ +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 +} |