3 # Copyright (c) Josef "Jeff" Sipek, 2006-2011
6 USAGE
="[-f] [-a | --all | -n <num> | <patchname>]"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename $0` directly is no longer supported." >&2
14 while [ $# -gt 0 ]; do
32 # "guilt-pop" or "guilt-pop foo" or "guilt-pop -n foo"
33 if [ -z "$all" ] && [ $# -gt 1 ]; then
38 if [ ! -z "$num" ]; then
39 if [ $# -gt 1 ] ||
[ $# -eq 0 ]; then
45 if [ ! -z "$all" ] && [ $# -gt 0 ]; then
50 [ ! -z "$all" ] && patch="-a"
52 if [ ! -s "$applied" ]; then
53 disp
"No patches applied."
55 elif [ "$patch" = "-a" ]; then
56 # we are supposed to pop all patches
58 sidx
=`wc -l < $applied`
60 elif [ ! -z "$num" ]; then
61 # we are supposed to pop a set number of patches
63 [ "$patch" -lt 0 ] && die
"Invalid number of patches to pop."
65 sidx
=`wc -l < $applied`
66 eidx
=`expr $sidx - $patch`
69 [ $eidx -lt 0 ] && eidx
=0
70 [ $eidx -eq $sidx ] && die
"No patches requested to be removed."
71 elif [ -z "$patch" ]; then
72 # we are supposed to pop only the current patch on the stack
74 sidx
=`wc -l < $applied`
77 # we're supposed to pop only up to a patch, make sure the patch is
80 eidx
=`cat $applied | grep -ne "^$patch$" | cut -d: -f 1`
81 if [ -z "$eidx" ]; then
82 die
"Patch $patch is not in the series/is not applied"
86 sidx
=`wc -l < $applied`
89 # make sure that there are no unapplied changes
90 # if we are forcing the pop, reset first
91 if [ ! -z "$force" ]; then
93 elif ! must_commit_first
; then
94 die
"Uncommited changes detected. Refresh first."
97 l
=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied`
99 pop_many_patches
`git rev-parse refs/patches/$branch/$l^` `expr $sidx - $eidx`
102 [ ! -z "$p" ] && disp
"Now at $p." || disp
"All patches popped."