3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE
="[ -f ] [-a | --all | -n <num> | <patchname>]"
11 while [ $# -gt 0 ]; do
34 # "guilt-push" or "guilt-push foo"
35 if [ -z "$all" ] && [ $# -gt 1 ]; then
40 if [ ! -z "$num" ]; then
41 if [ $# -gt 1 ] ||
[ $# -eq 0 ]; then
47 if [ ! -z "$all" ] && [ $# -gt 0 ]; then
52 [ ! -z "$all" ] && patch="-a"
54 if [ "$patch" = "-a" ]; then
55 # we are supposed to push all patches, get the last one out of
58 eidx
=`get_series | wc -l`
59 if [ $eidx -eq 0 ]; then
60 die
"There are no patches to push"
62 elif [ ! -z "$num" ]; then
63 # we are supposed to pop a set number of patches
65 [ "$patch" -lt 0 ] && die
"Invalid number of patches to push."
67 eidx
=`get_series | wc -l`
69 # calculate end index from current
70 tidx
=`wc -l < $applied`
71 tidx
=`expr $tidx + $patch`
74 [ $tidx -lt $eidx ] && eidx
=$tidx
76 elif [ -z "$patch" ]; then
77 # we are supposed to push only the next patch onto the stack
79 eidx
=`wc -l < $applied`
82 # we're supposed to push only up to a patch, make sure the patch is
85 eidx
=`get_series | grep -ne "^$patch\$" | cut -d: -f1`
86 if [ -z "$eidx" ]; then
87 die
"Patch $patch is not in the series"
91 # make sure that there are no unapplied changes
92 if ! must_commit_first
; then
93 die
"Uncommited changes detected. Refresh first."
96 # now, find the starting patch
97 sidx
=`wc -l < $applied`
100 get_series |
sed -n -e "${sidx},${eidx}p" |
while read p
102 disp
"Applying patch..$p"
103 if [ ! -f "$GUILT_DIR/$branch/$p" ]; then
104 die
"Patch $p does not exist. Aborting."
107 push_patch
"$p" $abort_flag
110 if [ $?
-eq 0 ]; then
111 disp
"Patch applied."
112 elif [ -z "$abort_flag" ]; then
113 die
"Patch applied with rejects. Fix it up, and refresh."
115 die
"To force apply this patch, use 'guilt push -f'"