zshrc: fix problems in vcs_info wrt older git versions
authorFrank Terbeck <ft@bewatermyfriend.org>
Sun, 7 Feb 2010 17:07:10 +0000 (18:07 +0100)
committerFrank Terbeck <ft@bewatermyfriend.org>
Sun, 7 Feb 2010 17:07:20 +0000 (18:07 +0100)
When rebases conflict and create a directory .dotest/, the branch name
ended up empty and that caused the git backend to abort collecting data
and return an error code.

That caused vcs_info to set up everything as if no version control
system controlled the directory.

Reported by Timo Boettcher, Thanks!

debian/changelog
etc/zsh/zshrc

index 36e068f..d8b5975 100644 (file)
@@ -9,12 +9,14 @@ grml-etc-core (0.3.78) unstable; urgency=low
   * zshrc: Fixed a bug in vcs_info which led to an endless loop, when
     a directory had really screwy premissions. Noticed by Christian
     Hofstaedtler.
+  * zshrc: Fix another vcs_info bug, wrt to backwards compatibility with
+    older git versions. Reported by Timo Boettcher.
 
   [ Ulrich Dangel ]
   * Added top configuration file to skel directory. Thanks to Andras
     Korn for the idea. [Closes: issue755]
 
- -- Michael Prokop <mika@grml.org>  Wed, 11 Nov 2009 21:47:16 +0100
+ -- Frank Terbeck <ft@grml.org>  Sun, 07 Feb 2010 18:04:11 +0100
 
 grml-etc-core (0.3.77) unstable; urgency=low
 
index f53c672..fe0c8f6 100644 (file)
@@ -1608,30 +1608,38 @@ VCS_INFO_git_getaction () { #{{{
 }
 # }}}
 VCS_INFO_git_getbranch () { #{{{
-    local gitbranch gitdir=$1
+    local gitbranch gitdir=$1 tmp actiondir
     local gitsymref='git symbolic-ref HEAD'
 
-    if    [[ -d "${gitdir}/rebase-apply" ]] \
-       || [[ -d "${gitdir}/rebase" ]]       \
-       || [[ -d "${gitdir}/../.dotest" ]]   \
-       || [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
+    actiondir=''
+    for tmp in "${gitdir}/rebase-apply" \
+               "${gitdir}/rebase"       \
+               "${gitdir}/../.dotest"; do
+        if [[ -d ${tmp} ]]; then
+            actiondir=${tmp}
+            break
+        fi
+    done
+    if [[ -n ${actiondir} ]]; then
+        gitbranch="$(${(z)gitsymref} 2> /dev/null)"
+        [[ -z ${gitbranch} ]] && [[ -r ${actiondir}/head-name ]] \
+            && gitbranch="$(< ${actiondir}/head-name)"
+
+    elif [[ -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)"
+        [[ -z ${gitbranch} ]] && gitbranch="$(< ${gitdir}/MERGE_HEAD)"
 
-    elif   [[ -f "${gitdir}/rebase-merge/interactive" ]] \
-        || [[ -d "${gitdir}/rebase-merge" ]] ; then
+    elif [[ -d "${gitdir}/rebase-merge" ]] ; then
         gitbranch="$(< ${gitdir}/rebase-merge/head-name)"
 
-    elif   [[ -f "${gitdir}/.dotest-merge/interactive" ]] \
-        || [[ -d "${gitdir}/.dotest-merge" ]] ; then
+    elif [[ -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)"
+            gitbranch="refs/tags/$(git describe --exact-match HEAD 2>/dev/null)"
 
             if [[ $? -ne 0 ]] ; then
                 gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
@@ -1639,7 +1647,7 @@ VCS_INFO_git_getbranch () { #{{{
         fi
     fi
 
-    printf '%s' "${gitbranch##refs/heads/}"
+    printf '%s' "${gitbranch##refs/[^/]##/}"
     return 0
 }
 # }}}