summaryrefslogtreecommitdiff
path: root/zshfunc/vcs-info/VCS_INFO_git_getbranch
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2009-06-27 10:33:51 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2009-06-27 10:33:51 +0000
commitcab4384bdb27f01a340323312cbcd8129d8d0569 (patch)
treebb41bbea0ed81e16ce91b959126319aa642fd607 /zshfunc/vcs-info/VCS_INFO_git_getbranch
parent9b19b5b9a1aae828101c901eee39491765ea4603 (diff)
Add vcs-info
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@398 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'zshfunc/vcs-info/VCS_INFO_git_getbranch')
-rw-r--r--zshfunc/vcs-info/VCS_INFO_git_getbranch35
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
+}