[PATCH] Make "guilt push" match "quilt push" when the patch doesn't apply
[guilt.git] / guilt-push
blob85b412245a8b85c1a4f7495b614dbadc3a390283
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 source "`dirname $0`/guilt"
8 abort_flag="abort"
10 USAGE="$USAGE [ -f ] [-a | --all | <patchname>]"
12 if [ "$1" == "-f" ]; then
13 abort_flag=""
14 shift
17 if [ $# -gt 1 ]; then
18 print_usage
19 exit 1
22 patch="$1"
24 if [ "$patch" = "--all" -o "$patch" = "-a" ]; then
25 # we are supposed to push all patches, get the last one out of
26 # series
28 eidx=`get_series | wc -l`
29 if [ $eidx -eq 0 ]; then
30 echo "There are no patches to push" >&2
31 exit 1
33 elif [ -z "$patch" ]; then
34 # we are supposed to push only the next patch onto the stack
36 eidx=`wc -l < $applied`
37 eidx=`expr $eidx + 1`
38 else
39 # we're supposed to push only up to a patch, make sure the patch is
40 # in the series
42 eidx=`get_series | grep -ne "^$patch\$" | cut -d: -f1`
43 if [ $eidx -eq 0 ]; then
44 echo "Patch $patch is not in the series" >&2
45 exit 1
49 # make sure that there are no unapplied changes
50 if ! must_commit_first; then
51 echo "Uncommited changes detected. Refresh first." >&2
52 exit 1
55 # now, find the starting patch
56 sidx=`wc -l < $applied`
57 sidx=`expr $sidx + 1`
59 idx=0
60 for p in `get_series`; do
61 idx=`expr $idx + 1`
62 [ $idx -lt $sidx ] && continue
63 [ $idx -gt $eidx ] && break
65 echo "Applying patch..$p"
66 if [ ! -f "$GUILT_DIR/$branch/$p" ]; then
67 echo "Patch $patch does not exist. Aborting." >&2
68 exit 1
71 push_patch $p $abort_flag
73 # bail if necessary
74 if [ $? -eq 0 ]; then
75 echo "Patch applied."
76 elif [ -z "$abort_flag" ]; then
77 echo "Patch applied with rejects. Fix it up, and refresh." >&2
78 exit 1
79 else
80 echo "To force apply this patch, use 'guilt push -f'" >&2
81 exit 1
83 done