zshrc: Handle non-repo .hg subdirectories
authorFrank Terbeck <ft@grml.org>
Fri, 29 Aug 2008 17:11:50 +0000 (19:11 +0200)
committerFrank Terbeck <ft@grml.org>
Fri, 29 Aug 2008 17:11:50 +0000 (19:11 +0200)
Such directories, that are not the .hg subdirectory of a mercurial
repository. Found by Karl Voit.

debian/changelog
etc/zsh/zshrc

index 4c7a499..4f12d95 100644 (file)
@@ -4,8 +4,10 @@ grml-etc-core (0.3.53) unstable; urgency=low
     rebase conflicts
   * zshrc: Make vcs_info() detect $GIT_DIR/svn and set the name of the
     vcs to 'git-svn'
+  * zshrc: Handle .hg subdirectories, that are not the .hg subdirectory
+    of a mercurial repository. Found by Karl Voit.
 
- -- Frank Terbeck <ft@grml.org>  Wed, 27 Aug 2008 22:35:09 +0200
+ -- Frank Terbeck <ft@grml.org>  Fri, 29 Aug 2008 19:08:28 +0200
 
 grml-etc-core (0.3.52) unstable; urgency=low
 
index 45abfd1..0bb49ad 100644 (file)
@@ -1097,6 +1097,10 @@ VCS_INFO_format () { # {{{
 # }}}
 VCS_INFO_realpath () { #{{{
     # replacing 'readlink -f', which is really not portable.
+
+    # If there *is* a chpwd() function unfunction it here.
+    # The *real* zsh does not loose its chpwd(), because we run
+    # in a different context (process substitution in $PROMPT).
     (( ${+functions[chpwd]} )) && unfunction chpwd
     setopt chaselinks
     cd $1 2>/dev/null && pwd
@@ -1269,14 +1273,24 @@ VCS_INFO_bzr_get_data () { # {{{
 
 VCS_INFO_detect_by_dir() {
     local dirname=${1}
-    local basedir="."
+    local basedir="." realbasedir
+
+    realbasedir=$(VCS_INFO_realpath ${basedir})
+    while [[ ${realbasedir} != '/' ]]; do
+        if [[ -n ${vcs_comm[detect_need_file]} ]] ; then
+            [[ -d ${basedir}/${dirname} ]] && \
+            [[ -f ${basedir}/${dirname}/${vcs_comm[detect_need_file]} ]] && \
+                break
+        else
+            [[ -d ${basedir}/${dirname} ]] && break
+        fi
 
-    while [[ ! -d ${basedir}/${dirname} ]]; do
         basedir=${basedir}/..
-        [[ $(VCS_INFO_realpath ${basedir}) = "/" ]] && return 1
+        realbasedir=$(VCS_INFO_realpath ${basedir})
     done
 
-    vcs_comm[basedir]=${basedir}
+    [[ ${realbasedir} == "/" ]] && return 1
+    vcs_comm[basedir]=${realbasedir}
     return 0
 }
 
@@ -1297,6 +1311,7 @@ VCS_INFO_git_detect() {
 
 VCS_INFO_hg_detect() {
     check_com -c hg || return 1
+    vcs_comm[detect_need_file]=branch
     VCS_INFO_detect_by_dir '.hg'
     return $?
 }