Mercurial > dotfiles
comparison .shell.d/50.hg_functions.sh @ 291:142fb39e4e55
hg-rebase-all: correctly use rebase result code
Exit status 1 can mean "nothing to rebase", which isn't helpful for
our case. Added a slight tangle of if statements to work around that.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 17 Oct 2012 08:21:28 -0500 |
parents | 93b24cdd2cce |
children | d9cc862e6308 |
comparison
equal
deleted
inserted
replaced
290:7a99481ab888 | 291:142fb39e4e55 |
---|---|
13 alias mq-snapshot=mq_snapshot | 13 alias mq-snapshot=mq_snapshot |
14 | 14 |
15 function hg_rebase_all () { | 15 function hg_rebase_all () { |
16 hg sum | egrep 'commit: .*\(clean\)$' || (echo 'abort: wc not clean' ; return 1) || return 1 | 16 hg sum | egrep 'commit: .*\(clean\)$' || (echo 'abort: wc not clean' ; return 1) || return 1 |
17 if [ "x$1" = "x" ] ; then | 17 if [ "x$1" = "x" ] ; then |
18 echo 'abort: give destination for rebase' | 18 echo 'abort: give destination for rebase' |
19 return 2 | 19 return 2 |
20 fi | 20 fi |
21 if [ "$1" = "tip" ] ; then | 21 if [ "$1" = "tip" ] ; then |
22 echo 'abort: tip is essentially never what you mean here' | 22 echo 'abort: tip is essentially never what you mean here' |
23 return 2 | 23 return 2 |
24 fi | 24 fi |
25 for b in $(hg book | sed 's/^ \*/ /' | awk '{ print $1 }') ; do | 25 for b in $(hg book | sed 's/^ \*/ /' | awk '{ print $1 }') ; do |
26 hg co --clean $b | 26 echo "About to rebase $b" |
27 hg rebase -d "$1" | 27 hg co --clean $b |
28 out=$(hg rebase -d "$1") | |
29 code=$? | |
30 grep "nothing to rebase" <(echo $out) | |
31 if [ $? = 0 ] ; then | |
32 echo 'moving on' | |
33 else | |
34 if [ $out -ne 0 ] ; then | |
35 echo "rebase exited with status $out" | |
36 return 3 | |
37 fi | |
38 fi | |
28 done | 39 done |
29 } | 40 } |
30 alias hg-rebase-all=hg_rebase_all | 41 alias hg-rebase-all=hg_rebase_all |
31 | 42 |
32 function hgsvnmergebranch() { | 43 function hgsvnmergebranch() { |
43 alias hg-svn-merge-branch=hgsvnmergebranch | 54 alias hg-svn-merge-branch=hgsvnmergebranch |
44 | 55 |
45 function hgsvnrebaseall() { | 56 function hgsvnrebaseall() { |
46 for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq` | 57 for b in `hg log -u 'Augie Fackler <durin42@gmail.com>' --template '{branches}\n' | sort | uniq` |
47 do | 58 do |
48 echo "rebase $b" | 59 echo "rebase $b" |
49 hg co $b | 60 hg co $b |
50 if [[ "$?" != "0" ]] ; then | 61 if [[ "$?" != "0" ]] ; then |
51 echo "abort: could not checkout $b" | 62 echo "abort: could not checkout $b" |
52 return | 63 return |
53 fi | 64 fi |
54 hg parent --svn > /dev/null | 65 hg parent --svn > /dev/null |
55 if [[ "$?" == "0" ]] ; then | 66 if [[ "$?" == "0" ]] ; then |
56 hg rebase --svn || return | 67 hg rebase --svn || return |
57 else | 68 else |
58 echo "Skip $b since it has a merge." | 69 echo "Skip $b since it has a merge." |
59 fi | 70 fi |
60 done | 71 done |
61 } | 72 } |
62 alias hg-svn-rebase-all=hgsvnrebaseall | 73 alias hg-svn-rebase-all=hgsvnrebaseall |
63 | 74 |
64 function hgamend() { | 75 function hgamend() { |
77 function hgsvnmkbranch() { | 88 function hgsvnmkbranch() { |
78 local upstream | 89 local upstream |
79 upstream=$(hg paths default | sed 's%/*$%%') | 90 upstream=$(hg paths default | sed 's%/*$%%') |
80 local branchname | 91 local branchname |
81 if [ "x$1" = "x" ] ; then | 92 if [ "x$1" = "x" ] ; then |
82 echo 'Must provide new branch name.' | 93 echo 'Must provide new branch name.' |
83 return 1 | 94 return 1 |
84 fi | 95 fi |
85 local d=`hg svn info | grep URL | sed 's/.*://'` | 96 local d=`hg svn info | grep URL | sed 's/.*://'` |
86 local br=`echo $d | awk '{ | 97 local br=`echo $d | awk '{ |
87 if ( index($1, "trunk") ) { | 98 if ( index($1, "trunk") ) { |
88 print "trunk" | 99 print "trunk" |
89 } else { | 100 } else { |
90 x = index($1, "branches") ; | 101 x = index($1, "branches") ; |
91 if ( x != 0 ) { | 102 if ( x != 0 ) { |
92 sub(".*/branches/", ""); | 103 sub(".*/branches/", ""); |
93 sub("/.*", ""); | 104 sub("/.*", ""); |
94 print $0 | 105 print $0 |
95 } | 106 } |
96 } | 107 } |
97 }'` | 108 }'` |
98 | 109 |
99 branchname=$br | 110 branchname=$br |
100 echo svn cp $upstream/$branchname $upstream/branches/$1 | 111 echo svn cp $upstream/$branchname $upstream/branches/$1 |
101 } | 112 } |
102 alias hg-svn-mkbranch=hgsvnmkbranch | 113 alias hg-svn-mkbranch=hgsvnmkbranch |