Mercurial > dotfiles
annotate .shell.d/50.vcs_functions.sh @ 43:f34194cad324
Fix to not strip whitespace in rst, since that format is broken to depend on trailing whitespace in some cases.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Thu, 05 Feb 2009 14:22:07 -0600 |
parents | 62bfb554ab85 |
children | 8946e6ae2747 |
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 | |
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
|
43 pushd $aa > /dev/null || continue |
0 | 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 | |
35
7e9269048856
Fix update_source_trees to also pull versioned mq if it exists.
Augie Fackler <durin42@gmail.com>
parents:
31
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 fi |
0 | 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() { | |
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
|
75 git branch 2> /dev/null > /dev/null |
0 | 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 | |
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 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 fi |
0 | 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 } |