3 # Copyright (c) Josef "Jeff" Sipek, 2006-2013
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 # Treat "guilt push" as "guilt push -n 1".
60 if [ -z "$patch" ]; then
65 if [ "$patch" = "-a" ]; then
66 # we are supposed to push all patches, get the last one out of
69 eidx
=`get_series | wc -l`
70 if [ $eidx -eq 0 ]; then
71 die
"There are no patches to push."
73 elif [ ! -z "$num" ]; then
74 # we are supposed to push a set number of patches
76 [ "$patch" -lt 0 ] && die
"Invalid number of patches to push."
78 eidx
=`get_series | wc -l`
80 # calculate end index from current
81 tidx
=`wc -l < "$applied"`
82 tidx
=`expr $tidx + $patch`
85 [ $tidx -lt $eidx ] && eidx
=$tidx
88 # we're supposed to push only up to a patch, make sure the patch is
91 eidx
=`get_series | grep -ne "^$patch\$" | cut -d: -f1`
92 if [ -z "$eidx" ]; then
93 die
"Patch $patch is not in the series or is guarded."
97 # make sure that there are no unapplied changes
98 if ! must_commit_first
; then
99 die
"Uncommited changes detected. Refresh first."
102 # now, find the starting patch
103 sidx
=`wc -l < "$applied"`
104 sidx
=`expr $sidx + 1`
106 # do we actually have to push anything?
107 if [ "$sidx" -gt "$eidx" ]; then
108 if [ "$sidx" -le "`get_series | wc -l`" ]; then
109 disp
"Patch is already applied."
111 disp
"File series fully applied, ends at patch `get_series | tail -n 1`"
113 if [ -n "$all" ]; then
120 get_series |
sed -n -e "${sidx},${eidx}p" |
while read p
122 disp
"Applying patch..$p"
123 if [ ! -f "$GUILT_DIR/$branch/$p" ]; then
124 die
"Patch $p does not exist. Aborting."
127 push_patch
"$p" $abort_flag
130 if [ $?
-eq 0 ]; then
131 disp
"Patch applied."
132 elif [ -z "$abort_flag" ]; then
133 die
"Patch applied with rejects. Fix it up, and refresh."
135 die
"To force apply this patch, use 'guilt push -f'"