Mercurial > dotfiles
annotate .shell.d/50.vcs_functions.sh @ 61:79c2c3932362
Add hg-svn-merge-branch which does all the steps of merging an hg branch for me.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Tue, 03 Mar 2009 11:32:17 -0600 |
| parents | 87b2ccf6ec44 |
| children | f9e826bd1f1b |
| 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 |
| 0 | 11 # Function to grab the url of an svn wc |
| 12 function svnurlof() { | |
| 13 local url | |
| 14 url=`svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
| 15 if [ x"$url" = "x" ] ; then | |
| 16 url=`git svn info $1 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` | |
| 17 fi | |
| 18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 fi |
| 0 | 24 url=`hg -R $dir svn info 2> /dev/null | grep '^URL: ' | sed 's/URL: //'` |
| 25 fi | |
| 26 if [ x"$url" = "x" ] ; then | |
| 27 echo -n 'No repo found (tried svn, git-svn, hgsvnclient)' | |
| 28 fi | |
| 29 echo $url | |
| 30 } | |
| 31 | |
|
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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 } |
|
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
|
43 |
|
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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 } |
|
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
|
50 |
|
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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 } 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
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 } |
|
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 } |
|
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 }'` |
|
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 |
|
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 branchname=$br |
|
47
e80bc65439ac
Too clever for my own good in this function.
Augie Fackler <durin42@gmail.com>
parents:
46
diff
changeset
|
74 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
|
75 } |
|
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 |
| 0 | 77 # Function to clean locks out of svn wcs |
| 78 function clean_svn_source_trees() { | |
| 79 for aa in */ ; do | |
| 80 pushd $aa > /dev/null | |
| 81 if [ -e .svn ] ; then | |
| 82 echo $aa 'is an svn checkout, cleaning' && svn cleanup | |
| 83 fi | |
| 84 popd > /dev/null | |
| 85 done | |
| 86 } | |
| 87 | |
| 88 # Function to update source trees of known VCS tools in the working dir. | |
| 89 # "known" means ones I'm forced to use on a regular basis | |
| 90 function update_source_trees() { | |
| 91 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
|
92 pushd $aa > /dev/null || continue |
| 0 | 93 if [ -e .svn ] ; then |
| 94 echo $aa 'is an svn checkout, updating' | |
| 95 svn up | |
| 96 elif [ -e .hg/svn ] ; then | |
| 97 echo $aa 'is an hg-svn checkout, updating' | |
| 98 hg svn pull | |
| 99 hg up | |
| 100 elif [ -e .git/svn ] ; then | |
| 101 echo $aa 'is a git-svn checkout, updating' | |
| 102 git svn fetch | |
| 103 git repack | |
| 104 git gc | |
| 105 elif [ -e .git ] ; then | |
| 106 echo $aa 'is a git checkout, updating' | |
| 107 git pull origin master | |
| 108 git repack | |
| 109 git gc | |
| 110 elif [ -e .hg ] ; then | |
| 111 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
|
112 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
|
113 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
|
114 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
|
115 fi |
| 0 | 116 elif [ -e _MTN ] ; then |
| 117 echo $aa "is an mtn co, updating" && mtn pull && mtn up | |
| 118 fi | |
| 119 popd > /dev/null | |
| 120 done | |
| 121 } | |
| 122 | |
| 123 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
|
124 git branch 2> /dev/null > /dev/null |
| 0 | 125 if [ $? = 0 ] ; then |
| 126 git branch --verbose | grep '^*' | sed 's/* //;s/ /:/;s/ .*//;s/:/ /' | |
| 127 return 0 | |
| 128 fi | |
| 129 # when wc-ng comes out, we'll probably do the following | |
| 130 # svn info 2> /dev/null > /dev/null | |
| 131 if [ -e .svn ] ; then | |
| 132 local d=`svn info | grep URL | sed 's/.*://'` | |
| 133 local br=`echo $d | awk '{ | |
| 134 if ( index($1, "trunk") ) { | |
| 135 print "trunk" | |
| 136 } else { | |
| 137 x = index($1, "branches") ; | |
| 138 if ( x != 0 ) { | |
| 139 sub(".*/branches/", ""); | |
| 140 sub("/.*", ""); | |
| 141 print $0 | |
| 142 } | |
| 143 } | |
| 144 }'` | |
| 145 local rev=`svn info | grep Revision | sed 's/.*: /r/'` | |
| 146 echo $br $rev | |
| 147 return 0 | |
| 148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 fi |
| 0 | 156 return 1 |
| 157 } | |
| 158 | |
| 159 # change to the root dir of the current wc | |
| 160 function wcroot() { | |
| 161 local root=`hg root 2> /dev/null` | |
| 162 if [ x$root != 'x' ] ; then | |
| 163 cd $root | |
| 164 return 0 | |
| 165 fi | |
| 166 git branch 2> /dev/null > /dev/null | |
| 167 if [ $? = 0 ] ; then | |
| 168 while [ ! -e .git ] ; do | |
| 169 cd .. | |
| 170 done | |
| 171 return 0 | |
| 172 fi | |
| 173 if [ -e .svn ] ; then | |
| 174 while [ -e ../.svn ] ; do | |
| 175 cd .. | |
| 176 done | |
| 177 return 0 | |
| 178 fi | |
| 179 echo No working copy found'!' | |
| 180 } |
