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 or is guarded."
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 # do we actually have to push anything?
101 if [ "$sidx" -gt "$eidx" ]; then
102 if [ "$sidx" -le "`get_series | wc -l`" ]; then
103 disp
"Patch is already applied."
105 disp
"File series fully applied, ends at patch `get_series | tail -1`"
110 get_series |
sed -n -e "${sidx},${eidx}p" |
while read p
112 disp
"Applying patch..$p"
113 if [ ! -f "$GUILT_DIR/$branch/$p" ]; then
114 die
"Patch $p does not exist. Aborting."
117 push_patch
"$p" $abort_flag
120 if [ $?
-eq 0 ]; then
121 disp
"Patch applied."
122 elif [ -z "$abort_flag" ]; then
123 die
"Patch applied with rejects. Fix it up, and refresh."
125 die
"To force apply this patch, use 'guilt push -f'"