annotate .shell.d/50.hg_functions.sh @ 364:2ac43cd7bbf7

hgimp: add location of topic repo
author Augie Fackler <raf@durin42.com>
date Fri, 11 Sep 2015 09:53:50 -0400
parents fc89d315942f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
210
0590f34b92a0 shell.d: split hg and git functions out of vcs functions
Augie Fackler <durin42@gmail.com>
parents: 204
diff changeset
1 ## hg_functions
0590f34b92a0 shell.d: split hg and git functions out of vcs functions
Augie Fackler <durin42@gmail.com>
parents: 204
diff changeset
2 # various hg utility functions
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3
60
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
4 function mq () {
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
5 ( wcroot ;
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
6 hg -R .hg/patches $@
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
7 )
87b2ccf6ec44 Improved mq now works anywhere inside the parent hg repo.
Augie Fackler <durin42@gmail.com>
parents: 58
diff changeset
8 }
13
c22ca1514f3b Add an alias to ease working with mq repos.
Augie Fackler <durin42@gmail.com>
parents: 10
diff changeset
9
253
93b24cdd2cce hg funcs: rename mq-snapshot to appease bash
Augie Fackler <durin42@gmail.com>
parents: 232
diff changeset
10 function mq_snapshot () {
200
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
11 mq ci -m "Applied on $(hg log -r qparent --template '{node|short}\n')"
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
12 }
253
93b24cdd2cce hg funcs: rename mq-snapshot to appease bash
Augie Fackler <durin42@gmail.com>
parents: 232
diff changeset
13 alias mq-snapshot=mq_snapshot
200
a563c21235ad vcs-functions: add mq-snapshot
Augie Fackler <durin42@gmail.com>
parents: 195
diff changeset
14
228
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
15 function hg_rebase_all () {
232
369d869082fd hg-rebase-all: corrected wc cleanliness check
Augie Fackler <durin42@gmail.com>
parents: 231
diff changeset
16 hg sum | egrep 'commit: .*\(clean\)$' || (echo 'abort: wc not clean' ; return 1) || return 1
228
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
17 if [ "x$1" = "x" ] ; then
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
18 echo 'abort: give destination for rebase'
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
19 return 2
228
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
20 fi
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
21 if [ "$1" = "tip" ] ; then
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
22 echo 'abort: tip is essentially never what you mean here'
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
23 return 2
228
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
24 fi
309
74990ae54bd2 hg-rebase-all: defend against no bookmarks being set
Augie Fackler <raf@durin42.com>
parents: 305
diff changeset
25 marks=$(hg book | sed 's/^ \*/ /' | awk '{ print $1 }')
74990ae54bd2 hg-rebase-all: defend against no bookmarks being set
Augie Fackler <raf@durin42.com>
parents: 305
diff changeset
26 if [ "$marks" = "no bookmarks set" ] ; then
74990ae54bd2 hg-rebase-all: defend against no bookmarks being set
Augie Fackler <raf@durin42.com>
parents: 305
diff changeset
27 echo "no bookmarks set, nothing to rebase"
74990ae54bd2 hg-rebase-all: defend against no bookmarks being set
Augie Fackler <raf@durin42.com>
parents: 305
diff changeset
28 fi
74990ae54bd2 hg-rebase-all: defend against no bookmarks being set
Augie Fackler <raf@durin42.com>
parents: 305
diff changeset
29 for b in $(echo $marks) ; do
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
30 echo "About to rebase $b"
349
fc89d315942f hg_rebase_all: optimize by using -b instead of checking out revision to rebase
Augie Fackler <raf@durin42.com>
parents: 320
diff changeset
31 out=$(hg rebase -d "$1" -b "$b")
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
32 code=$?
320
2b129f63d910 hg-rebase-all: remove bashism
Augie Fackler <raf@durin42.com>
parents: 309
diff changeset
33 echo $out | grep "nothing to rebase"
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
34 if [ $? = 0 ] ; then
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
35 echo 'moving on'
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
36 else
305
d9cc862e6308 hg_rebase_all: fix exit status check
Augie Fackler <raf@durin42.com>
parents: 291
diff changeset
37 if [ $code -ne 0 ] ; then
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
38 echo "rebase exited with status $out"
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
39 return 3
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
40 fi
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
41 fi
228
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
42 done
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
43 }
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
44 alias hg-rebase-all=hg_rebase_all
0c8939baa35c hg-rebase-all: new function to rebase all bookmarked revisions
Augie Fackler <durin42@gmail.com>
parents: 210
diff changeset
45
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
46 function hgsvnmergebranch() {
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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
57 alias hg-svn-merge-branch=hgsvnmergebranch
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
58
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
59 function hgsvnrebaseall() {
69
5232fa3d7ad3 Changes required by log being back to the default.
Augie Fackler <durin42@gmail.com>
parents: 67
diff changeset
60 for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq`
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
61 do
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
62 echo "rebase $b"
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
63 hg co $b
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
64 if [[ "$?" != "0" ]] ; then
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
65 echo "abort: could not checkout $b"
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
66 return
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
67 fi
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
68 hg parent --svn > /dev/null
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
69 if [[ "$?" == "0" ]] ; then
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
70 hg rebase --svn || return
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
71 else
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
72 echo "Skip $b since it has a merge."
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
73 fi
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
74 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
75 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
76 alias hg-svn-rebase-all=hgsvnrebaseall
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
77
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
78 function hgamend() {
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
79 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
80 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
81 alias hg-amend=hgamend
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
82
204
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
83 function hg_verify_all() {
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
84 for x in $(find . -name '.hg') ; do
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
85 y=$(dirname $x)
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
86 echo $y
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
87 hg verify -R $y
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
88 done
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
89 }
9e45ac5350fd vcs funcs: tools for verifying hg or git repos, packing git repos
Augie Fackler <durin42@gmail.com>
parents: 200
diff changeset
90
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
91 function hgsvnmkbranch() {
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 local upstream
129
1286c27cf0c0 Need to use paths default instead of the outdated svn url now.
Augie Fackler <durin42@gmail.com>
parents: 115
diff changeset
93 upstream=$(hg paths default | sed 's%/*$%%')
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
94 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
95 if [ "x$1" = "x" ] ; then
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
96 echo 'Must provide new branch name.'
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
97 return 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
98 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
99 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
100 local br=`echo $d | awk '{
291
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
101 if ( index($1, "trunk") ) {
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
102 print "trunk"
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
103 } else {
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
104 x = index($1, "branches") ;
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
105 if ( x != 0 ) {
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
106 sub(".*/branches/", "");
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
107 sub("/.*", "");
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
108 print $0
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
109 }
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
110 }
142fb39e4e55 hg-rebase-all: correctly use rebase result code
Augie Fackler <raf@durin42.com>
parents: 253
diff changeset
111 }'`
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
112
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
113 branchname=$br
47
e80bc65439ac Too clever for my own good in this function.
Augie Fackler <durin42@gmail.com>
parents: 46
diff changeset
114 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
115 }
133
5b0b8ad2cb2c vcs_functions: some versions of the shell don't like - in function names.
Augie Fackler <durin42@gmail.com>
parents: 129
diff changeset
116 alias hg-svn-mkbranch=hgsvnmkbranch