comparison .zsh/50.vcs_functions.zsh @ 0:c30d68fbd368

Initial import from svn.
author Augie Fackler <durin42@gmail.com>
date Wed, 26 Nov 2008 10:56:09 -0600
parents
children b4bfce76123f
comparison
equal deleted inserted replaced
-1:000000000000 0:c30d68fbd368
1 ## vcs_functions
2 # This file contains a handful of functions that relate to using some version
3 # control tool or other.
4
5 # Function to grab the url of an svn wc
6 function svnurlof() {
7 local url
8 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
9 if [ x"$url" = "x" ] ; then
10 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
11 fi
12 if [ x"$url" = "x" ] ; then
13 local dir
14 dir=$1
15 if [ x"$dir" = "x" ] ; then
16 dir="."
17 fi
18 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'`
19 fi
20 if [ x"$url" = "x" ] ; then
21 echo -n 'No repo found (tried svn, git-svn, hgsvnclient)'
22 fi
23 echo $url
24 }
25
26 # Function to clean locks out of svn wcs
27 function clean_svn_source_trees() {
28 for aa in */ ; do
29 pushd $aa > /dev/null
30 if [ -e .svn ] ; then
31 echo $aa 'is an svn checkout, cleaning' && svn cleanup
32 fi
33 popd > /dev/null
34 done
35 }
36
37 # Function to update source trees of known VCS tools in the working dir.
38 # "known" means ones I'm forced to use on a regular basis
39 function update_source_trees() {
40 for aa in */ ; do
41 pushd $aa > /dev/null
42 if [ -e .svn ] ; then
43 echo $aa 'is an svn checkout, updating'
44 svn up
45 elif [ -e .hg/svn ] ; then
46 echo $aa 'is an hg-svn checkout, updating'
47 hg svn pull
48 hg svn gentags
49 hg up
50 elif [ -e .git/svn ] ; then
51 echo $aa 'is a git-svn checkout, updating'
52 git svn fetch
53 git repack
54 git gc
55 elif [ -e .git ] ; then
56 echo $aa 'is a git checkout, updating'
57 git pull origin master
58 git repack
59 git gc
60 elif [ -e .hg ] ; then
61 echo $aa 'is an hg checkout, updating' && hg pull && hg up
62 elif [ -e _MTN ] ; then
63 echo $aa "is an mtn co, updating" && mtn pull && mtn up
64 fi
65 popd > /dev/null
66 done
67 }
68
69 function vcs_current_branch() {
70 hg branch 2> /dev/null > /dev/null
71 if [ $? = 0 ] ; then
72 local br=`hg branch | head -c 10`
73 local rid=`hg parents | head -n 1 | awk '{print $2}' | head -c 7`
74 echo "$br $rid"
75 return 0
76 fi
77 git branch 2> /dev/null > /dev/null
78 if [ $? = 0 ] ; then
79 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /'
80 return 0
81 fi
82 # when wc-ng comes out, we'll probably do the following
83 # svn info 2> /dev/null > /dev/null
84 if [ -e .svn ] ; then
85 local d=`svn info | grep URL | sed 's/.*://'`
86 local br=`echo $d | awk '{
87 if ( index($1, "trunk") ) {
88 print "trunk"
89 } else {
90 x = index($1, "branches") ;
91 if ( x != 0 ) {
92 sub(".*/branches/", "");
93 sub("/.*", "");
94 print $0
95 }
96 }
97 }'`
98 local rev=`svn info | grep Revision | sed 's/.*: /r/'`
99 echo $br $rev
100 return 0
101 fi
102 return 1
103 }
104
105 # change to the root dir of the current wc
106 function wcroot() {
107 local root=`hg root 2> /dev/null`
108 if [ x$root != 'x' ] ; then
109 cd $root
110 return 0
111 fi
112 git branch 2> /dev/null > /dev/null
113 if [ $? = 0 ] ; then
114 while [ ! -e .git ] ; do
115 cd ..
116 done
117 return 0
118 fi
119 if [ -e .svn ] ; then
120 while [ -e ../.svn ] ; do
121 cd ..
122 done
123 return 0
124 fi
125 echo No working copy found'!'
126 }