3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE
="[-f] [-a | --all | -n <num> | <patchname>]"
27 # "guilt-pop" or "guilt-pop foo" or "guilt-pop -n foo"
28 if [ -z "$all" ] && [ $# -gt 1 ]; then
33 if [ ! -z "$num" ]; then
34 if [ $# -gt 1 ] ||
[ $# -eq 0 ]; then
40 if [ ! -z "$all" ] && [ $# -gt 0 ]; then
45 [ ! -z "$all" ] && patch="-a"
47 if [ ! -s "$applied" ]; then
48 disp
"No patches applied."
50 elif [ "$patch" = "-a" ]; then
51 # we are supposed to pop all patches
53 sidx
=`wc -l < $applied`
55 elif [ ! -z "$num" ]; then
56 # we are supposed to pop a set number of patches
58 [ "$patch" -lt 0 ] && die
"Invalid number of patches to pop."
60 sidx
=`wc -l < $applied`
61 eidx
=`expr $sidx - $patch`
64 [ $eidx -lt 0 ] && eidx
=0
65 [ $eidx -eq $sidx ] && die
"No patches requested to be removed."
66 elif [ -z "$patch" ]; then
67 # we are supposed to pop only the current patch on the stack
69 sidx
=`wc -l < $applied`
72 # we're supposed to pop only up to a patch, make sure the patch is
75 eidx
=`cat $applied | grep -ne "^$patch$" | cut -d: -f 1`
76 if [ -z "$eidx" ]; then
77 die
"Patch $patch is not in the series/is not applied"
81 sidx
=`wc -l < $applied`
84 # make sure that there are no unapplied changes
85 # if we are forcing the pop, reset first
86 if [ ! -z "$force" ]; then
88 elif ! must_commit_first
; then
89 die
"Uncommited changes detected. Refresh first."
92 l
=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied`
94 pop_many_patches
`git rev-parse refs/patches/$branch/$l^` `expr $sidx - $eidx`
97 [ ! -z "$p" ] && disp
"Now at $p." || disp
"All patches popped."