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
16 while [ $# -gt 0 ]; do
39 # "guilt-push" or "guilt-push foo"
40 if [ -z "$all" ] && [ $# -gt 1 ]; then
45 if [ ! -z "$num" ]; then
46 if [ $# -gt 1 ] ||
[ $# -eq 0 ]; then
52 if [ ! -z "$all" ] && [ $# -gt 0 ]; then
57 [ ! -z "$all" ] && patch="-a"
59 if [ "$patch" = "-a" ]; then
60 # we are supposed to push all patches, get the last one out of
63 eidx
=`get_series | wc -l`
64 if [ $eidx -eq 0 ]; then
65 die
"There are no patches to push."
67 elif [ ! -z "$num" ]; then
68 # we are supposed to pop a set number of patches
70 [ "$patch" -lt 0 ] && die
"Invalid number of patches to push."
72 eidx
=`get_series | wc -l`
74 # calculate end index from current
75 tidx
=`wc -l < $applied`
76 tidx
=`expr $tidx + $patch`
79 [ $tidx -lt $eidx ] && eidx
=$tidx
81 elif [ -z "$patch" ]; then
82 # we are supposed to push only the next patch onto the stack
84 eidx
=`wc -l < $applied`
87 # we're supposed to push only up to a patch, make sure the patch is
90 eidx
=`get_series | grep -ne "^$patch\$" | cut -d: -f1`
91 if [ -z "$eidx" ]; then
92 die
"Patch $patch is not in the series or is guarded."
96 # make sure that there are no unapplied changes
97 if ! must_commit_first
; then
98 die
"Uncommited changes detected. Refresh first."
101 # now, find the starting patch
102 sidx
=`wc -l < $applied`
103 sidx
=`expr $sidx + 1`
105 # do we actually have to push anything?
106 if [ "$sidx" -gt "$eidx" ]; then
107 if [ "$sidx" -le "`get_series | wc -l`" ]; then
108 disp
"Patch is already applied."
110 disp
"File series fully applied, ends at patch `get_series | tail -n 1`"
115 get_series |
sed -n -e "${sidx},${eidx}p" |
while read p
117 disp
"Applying patch..$p"
118 if [ ! -f "$GUILT_DIR/$branch/$p" ]; then
119 die
"Patch $p does not exist. Aborting."
122 push_patch
"$p" $abort_flag
125 if [ $?
-eq 0 ]; then
126 disp
"Patch applied."
127 elif [ -z "$abort_flag" ]; then
128 die
"Patch applied with rejects. Fix it up, and refresh."
130 die
"To force apply this patch, use 'guilt push -f'"