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 [ "$patch" = "-a" ]; then
38 # we are supposed to pop all patches
40 sidx
=`wc -l < $applied`
42 elif [ -z "$patch" ]; then
43 # we are supposed to pop only the current patch on the stack
45 sidx
=`wc -l < $applied`
48 # we're supposed to pop only up to a patch, make sure the patch is
51 eidx
=`cat $applied | grep -ne "^[0-9a-f]\{40\}:$patch\$" | cut -d: -f 1`
52 if [ -z "$eidx" ]; then
53 die
"Patch $patch is not in the series/is not applied"
57 sidx
=`wc -l < $applied`
60 # make sure that there are no unapplied changes
61 # if we are forcing the pop, reset first
62 if [ ! -z "$force" ]; then
63 cd "$TOP_DIR" >&2 >/dev
/null
66 elif ! must_commit_first
; then
67 die
"Uncommited changes detected. Refresh first."
70 l
=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied`
72 pop_many_patches
`echo $l | cut -d: -f1`^
`expr $sidx - $eidx`
75 [ ! -z "$p" ] && echo "Now at $p." ||
echo "All patches popped."