Mercurial > dotfiles
annotate .shell.d/50.vcs_functions.sh @ 63:1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 11 Mar 2009 10:47:45 -0500 |
parents | f9e826bd1f1b |
children | 9f8bd97da0d4 |
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 | |
60
87b2ccf6ec44
Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents:
58
diff
changeset
|
5 function mq () { |
87b2ccf6ec44
Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents:
58
diff
changeset
|
6 ( wcroot ; |
87b2ccf6ec44
Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents:
58
diff
changeset
|
7 hg -R .hg/patches $@ |
87b2ccf6ec44
Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents:
58
diff
changeset
|
8 ) |
87b2ccf6ec44
Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents:
58
diff
changeset
|
9 } |
13
c22ca1514f3b
Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
10 |
63
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
11 function ez-svn-sync() { |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
12 local url |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
13 local repo |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
14 repo=$1 |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
15 url=$2 |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
16 svnadmin create $repo |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
17 echo '#!/bin/sh' >> $repo/hooks/pre-revprop-change |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
18 echo 'exit 0' >> $repo/hooks/pre-revprop-change |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
19 chmod +x $repo/hooks/pre-revprop-change |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
20 svnsync init file://`pwd`/$repo $url |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
21 svnsync sync file://`pwd`/$repo |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
22 } |
1b4067cc97ca
Add a function to svnsync easier. Done this too many times because of hgsubversion.
Augie Fackler <durin42@gmail.com>
parents:
62
diff
changeset
|
23 |
0 | 24 # Function to grab the url of an svn wc |
25 function svnurlof() { | |
26 local url | |
27 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
28 if [ x"$url" = "x" ] ; then | |
29 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
30 fi | |
31 if [ x"$url" = "x" ] ; then | |
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
32 local dir |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
33 dir=$1 |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
34 if [ x"$dir" = "x" ] ; then |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
35 dir="." |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
36 fi |
0 | 37 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` |
38 fi | |
39 if [ x"$url" = "x" ] ; then | |
40 echo -n 'No repo found (tried svn, git-svn, hgsvnclient)' | |
41 fi | |
42 echo $url | |
43 } | |
44 | |
61
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
45 function hg-svn-merge-branch() { |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
46 local targetrev |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
47 local striprev |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
48 targetrev=$(hg id | cut -d ' ' -f 1) |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
49 hg merge $1 |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
50 hg ci -m "Merging $1" |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
51 striprev=$(hg id | cut -d ' ' -f 1) |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
52 hg co $targetrev |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
53 hg diff -r$targetrev:$striprev | hg import - -m "Merged branch $1." |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
54 hg strip $striprev |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
55 } |
79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
Augie Fackler <durin42@gmail.com>
parents:
60
diff
changeset
|
56 |
58
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
57 function hg-svn-rebase-all() { |
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
58 for b in `hg llog -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq` |
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
59 do |
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
60 hg co $b && hg svn rebase || return |
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
61 done |
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
62 } |
20834b97b814
Add function to rebase all local named branches to HEAD of their parent svn branch.
Augie Fackler <durin42@gmail.com>
parents:
47
diff
changeset
|
63 |
62
f9e826bd1f1b
Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents:
61
diff
changeset
|
64 function hg-ammend() { |
f9e826bd1f1b
Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents:
61
diff
changeset
|
65 hg qimport -r . && hg qref && hg qfin qtip |
f9e826bd1f1b
Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents:
61
diff
changeset
|
66 } |
f9e826bd1f1b
Add a function to ammend the latest revision in hg. I don't do this often, but when I need it it is handy.
Augie Fackler <durin42@gmail.com>
parents:
61
diff
changeset
|
67 |
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
68 function hg-svn-mkbranch() { |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
69 local upstream |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
70 upstream=$(hg svn url) |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
71 local branchname |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
72 if [ "x$1" = "x" ] ; then |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
73 echo 'Must provide new branch name.' |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
74 return 1 |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
75 fi |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
76 local d=`hg svn info | grep URL | sed 's/.*://'` |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
77 local br=`echo $d | awk '{ |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
78 if ( index($1, "trunk") ) { |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
79 print "trunk" |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
80 } else { |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
81 x = index($1, "branches") ; |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
82 if ( x != 0 ) { |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
83 sub(".*/branches/", ""); |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
84 sub("/.*", ""); |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
85 print $0 |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
86 } |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
87 } |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
88 }'` |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
89 |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
90 branchname=$br |
47
e80bc65439ac
Too clever for my own good in this function.
Augie Fackler <durin42@gmail.com>
parents:
46
diff
changeset
|
91 echo svn cp $upstream/$branchname $upstream/branches/$1 |
46
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
92 } |
8946e6ae2747
Stopgap hg-svn-mkbranch command to save me typing until the feature goes into hgsubversion itself.
Augie Fackler <durin42@gmail.com>
parents:
39
diff
changeset
|
93 |
0 | 94 # Function to clean locks out of svn wcs |
95 function clean_svn_source_trees() { | |
96 for aa in */ ; do | |
97 pushd $aa > /dev/null | |
98 if [ -e .svn ] ; then | |
99 echo $aa 'is an svn checkout, cleaning' && svn cleanup | |
100 fi | |
101 popd > /dev/null | |
102 done | |
103 } | |
104 | |
105 # Function to update source trees of known VCS tools in the working dir. | |
106 # "known" means ones I'm forced to use on a regular basis | |
107 function update_source_trees() { | |
108 for aa in */ ; do | |
31
a5691a22c92b
Fix a bug in update_source_trees where it could eat any existing dirstack
Augie Fackler <durin42@gmail.com>
parents:
16
diff
changeset
|
109 pushd $aa > /dev/null || continue |
0 | 110 if [ -e .svn ] ; then |
111 echo $aa 'is an svn checkout, updating' | |
112 svn up | |
113 elif [ -e .hg/svn ] ; then | |
114 echo $aa 'is an hg-svn checkout, updating' | |
115 hg svn pull | |
116 hg up | |
117 elif [ -e .git/svn ] ; then | |
118 echo $aa 'is a git-svn checkout, updating' | |
119 git svn fetch | |
120 git repack | |
121 git gc | |
122 elif [ -e .git ] ; then | |
123 echo $aa 'is a git checkout, updating' | |
124 git pull origin master | |
125 git repack | |
126 git gc | |
127 elif [ -e .hg ] ; then | |
128 echo $aa 'is an hg checkout, updating' && hg pull && hg up | |
35
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
129 if [ -e .hg/patches/.hg ] ; then |
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
130 echo $aa 'has an mq, updating that too...' |
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
131 hg -R .hg/patches pull -u |
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
132 fi |
0 | 133 elif [ -e _MTN ] ; then |
134 echo $aa "is an mtn co, updating" && mtn pull && mtn up | |
135 fi | |
136 popd > /dev/null | |
137 done | |
138 } | |
139 | |
140 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
|
141 git branch 2> /dev/null > /dev/null |
0 | 142 if [ $? = 0 ] ; then |
143 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /' | |
144 return 0 | |
145 fi | |
146 # when wc-ng comes out, we'll probably do the following | |
147 # svn info 2> /dev/null > /dev/null | |
148 if [ -e .svn ] ; then | |
149 local d=`svn info | grep URL | sed 's/.*://'` | |
150 local br=`echo $d | awk '{ | |
151 if ( index($1, "trunk") ) { | |
152 print "trunk" | |
153 } else { | |
154 x = index($1, "branches") ; | |
155 if ( x != 0 ) { | |
156 sub(".*/branches/", ""); | |
157 sub("/.*", ""); | |
158 print $0 | |
159 } | |
160 } | |
161 }'` | |
162 local rev=`svn info | grep Revision | sed 's/.*: /r/'` | |
163 echo $br $rev | |
164 return 0 | |
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 fi |
0 | 173 return 1 |
174 } | |
175 | |
176 # change to the root dir of the current wc | |
177 function wcroot() { | |
178 local root=`hg root 2> /dev/null` | |
179 if [ x$root != 'x' ] ; then | |
180 cd $root | |
181 return 0 | |
182 fi | |
183 git branch 2> /dev/null > /dev/null | |
184 if [ $? = 0 ] ; then | |
185 while [ ! -e .git ] ; do | |
186 cd .. | |
187 done | |
188 return 0 | |
189 fi | |
190 if [ -e .svn ] ; then | |
191 while [ -e ../.svn ] ; do | |
192 cd .. | |
193 done | |
194 return 0 | |
195 fi | |
196 echo No working copy found'!' | |
197 } |