From: Frank Terbeck Date: Sun, 7 Feb 2010 17:07:10 +0000 (+0100) Subject: zshrc: fix problems in vcs_info wrt older git versions X-Git-Tag: v0.3.79~4 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=85d167395b54475847233b5a1c5edb81c1760bec zshrc: fix problems in vcs_info wrt older git versions 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! --- diff --git a/debian/changelog b/debian/changelog index 36e068f..d8b5975 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Wed, 11 Nov 2009 21:47:16 +0100 + -- Frank Terbeck Sun, 07 Feb 2010 18:04:11 +0100 grml-etc-core (0.3.77) unstable; urgency=low diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index f53c672..fe0c8f6 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -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 } # }}}