comparison .shell.d/50.vcs_functions.sh @ 39:62bfb554ab85

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