Mercurial > dotfiles
comparison .shell.d/50.vcs_functions.sh @ 283:533bde18976e
find_dvcs_root: new function to find dvcs root dir more safely
This compares the discovered root dir lengths in order to give the
most specific repository path possible.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Tue, 27 Mar 2012 13:41:40 -0500 |
| parents | 3350b219b653 |
| children | 901e85174513 |
comparison
equal
deleted
inserted
replaced
| 282:ba2fd0bed641 | 283:533bde18976e |
|---|---|
| 133 return 0 | 133 return 0 |
| 134 fi | 134 fi |
| 135 return 1 | 135 return 1 |
| 136 } | 136 } |
| 137 | 137 |
| 138 function find_dvcs_root() { | |
| 139 local hgroot=`hg root 2> /dev/null` | |
| 140 local gitroot=$(git rev-parse --show-toplevel 2> /dev/null) | |
| 141 local hglen=$(expr length $hgroot) | |
| 142 local gitlen=$(expr length $gitroot) | |
| 143 if [ $hglen -ge $gitlen ] ; then | |
| 144 if [ -n "$hgroot" ] ; then | |
| 145 echo $hgroot | |
| 146 return 0 | |
| 147 fi | |
| 148 else | |
| 149 if [ -n "$gitroot" ] ; then | |
| 150 echo $gitroot | |
| 151 return 0 | |
| 152 fi | |
| 153 fi | |
| 154 return 1 | |
| 155 } | |
| 156 | |
| 138 # change to the root dir of the current wc | 157 # change to the root dir of the current wc |
| 139 function wcroot() { | 158 function wcroot() { |
| 140 local root=`hg root 2> /dev/null` | 159 local dvcsroot=$(find_dvcs_root) |
| 141 if [ x$root != 'x' ] ; then | 160 if [ -n $dvcsroot ] ; then |
| 142 cd $root | 161 cd $dvcsroot |
| 143 return 0 | |
| 144 fi | |
| 145 root=$(git rev-parse --show-toplevel 2> /dev/null) | |
| 146 if [ $? = 0 ] ; then | |
| 147 cd $root | |
| 148 return 0 | 162 return 0 |
| 149 fi | 163 fi |
| 150 if [ -e .svn ] ; then | 164 if [ -e .svn ] ; then |
| 151 while [ -e ../.svn ] ; do | 165 while [ -e ../.svn ] ; do |
| 152 cd .. | 166 cd .. |
