Mercurial > dotfiles
annotate .zsh/50.vcs_functions.zsh @ 13:c22ca1514f3b
Add an alias to ease working with mq repos.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 03 Dec 2008 22:55:45 -0600 |
parents | b4bfce76123f |
children | 0de17fe9c428 |
rev | line source |
---|---|
0 | 1 ## vcs_functions |
2 # This file contains a handful of functions that relate to using some version | |
3 # control tool or other. | |
4 | |
13
c22ca1514f3b
Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
5 alias mq='hg -R .hg/patches' |
c22ca1514f3b
Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
6 |
0 | 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 | |
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 svn gentags | |
51 hg up | |
52 elif [ -e .git/svn ] ; then | |
53 echo $aa 'is a git-svn checkout, updating' | |
54 git svn fetch | |
55 git repack | |
56 git gc | |
57 elif [ -e .git ] ; then | |
58 echo $aa 'is a git checkout, updating' | |
59 git pull origin master | |
60 git repack | |
61 git gc | |
62 elif [ -e .hg ] ; then | |
63 echo $aa 'is an hg checkout, updating' && hg pull && hg up | |
64 elif [ -e _MTN ] ; then | |
65 echo $aa "is an mtn co, updating" && mtn pull && mtn up | |
66 fi | |
67 popd > /dev/null | |
68 done | |
69 } | |
70 | |
71 function vcs_current_branch() { | |
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
72 git branch 2> /dev/null > /dev/null |
0 | 73 if [ $? = 0 ] ; then |
74 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /' | |
75 return 0 | |
76 fi | |
77 # when wc-ng comes out, we'll probably do the following | |
78 # svn info 2> /dev/null > /dev/null | |
79 if [ -e .svn ] ; then | |
80 local d=`svn info | grep URL | sed 's/.*://'` | |
81 local br=`echo $d | awk '{ | |
82 if ( index($1, "trunk") ) { | |
83 print "trunk" | |
84 } else { | |
85 x = index($1, "branches") ; | |
86 if ( x != 0 ) { | |
87 sub(".*/branches/", ""); | |
88 sub("/.*", ""); | |
89 print $0 | |
90 } | |
91 } | |
92 }'` | |
93 local rev=`svn info | grep Revision | sed 's/.*: /r/'` | |
94 echo $br $rev | |
95 return 0 | |
96 fi | |
10
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
97 hg branch 2> /dev/null > /dev/null |
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
98 if [ $? = 0 ] ; then |
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
99 local br=`hg branch | head -c 10` |
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
100 local rid=`hg parents | head -n 1 | awk '{print $2}' | head -c 7` |
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
101 echo "$br $rid" |
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
102 return 0 |
b4bfce76123f
Reorder these checks. With my home being in hg, it was winning over any other
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
103 fi |
0 | 104 return 1 |
105 } | |
106 | |
107 # change to the root dir of the current wc | |
108 function wcroot() { | |
109 local root=`hg root 2> /dev/null` | |
110 if [ x$root != 'x' ] ; then | |
111 cd $root | |
112 return 0 | |
113 fi | |
114 git branch 2> /dev/null > /dev/null | |
115 if [ $? = 0 ] ; then | |
116 while [ ! -e .git ] ; do | |
117 cd .. | |
118 done | |
119 return 0 | |
120 fi | |
121 if [ -e .svn ] ; then | |
122 while [ -e ../.svn ] ; do | |
123 cd .. | |
124 done | |
125 return 0 | |
126 fi | |
127 echo No working copy found'!' | |
128 } |