3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE
="[-f] [-a | --all | <patchname>]"
24 # "guilt-pop" or "guilt-pop foo"
25 if [ -z "$all" ] && [ $# -gt 1 ]; then
30 if [ ! -z "$all" ] && [ $# -gt 0 ]; then
35 [ ! -z "$all" ] && patch="-a"
37 if [ ! -s "$applied" ]; then
38 echo "No patches applied."
40 elif [ "$patch" = "-a" ]; then
41 # we are supposed to pop all patches
43 sidx
=`wc -l < $applied`
45 elif [ -z "$patch" ]; then
46 # we are supposed to pop only the current patch on the stack
48 sidx
=`wc -l < $applied`
51 # we're supposed to pop only up to a patch, make sure the patch is
54 eidx
=`cat $applied | grep -ne "^[0-9a-f]\{40\}:$patch\$" | cut -d: -f 1`
55 if [ -z "$eidx" ]; then
56 die
"Patch $patch is not in the series/is not applied"
60 sidx
=`wc -l < $applied`
63 # make sure that there are no unapplied changes
64 # if we are forcing the pop, reset first
65 if [ ! -z "$force" ]; then
66 cd "$TOP_DIR" >&2 >/dev
/null
69 elif ! must_commit_first
; then
70 die
"Uncommited changes detected. Refresh first."
73 l
=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied`
75 pop_many_patches
`echo $l | cut -d: -f1`^
`expr $sidx - $eidx`
78 [ ! -z "$p" ] && echo "Now at $p." ||
echo "All patches popped."