Guilt v0.31.2
[guilt/mob.git] / guilt-push
blob018f9ac6438a8e27df8c1561ec25b5175c153394
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[ -f ] [-a | --all | -n <num> | <patchname>]"
7 . `dirname $0`/guilt
9 abort_flag="abort"
11 while [ $# -gt 0 ]; do
12 case "$1" in
13 -f)
14 abort_flag=""
16 -a|--all)
17 all=t
19 -n)
20 num=t
23 break
25 esac
26 shift
27 done
30 if [ $# -gt 1 ]; then
31 usage
34 # "guilt-push" or "guilt-push foo"
35 if [ -z "$all" ] && [ $# -gt 1 ]; then
36 usage
39 # "guilt-push -n foo"
40 if [ ! -z "$num" ]; then
41 if [ $# -gt 1 ] || [ $# -eq 0 ]; then
42 usage
46 # "guilt-push -a"
47 if [ ! -z "$all" ] && [ $# -gt 0 ]; then
48 usage
51 patch="$1"
52 [ ! -z "$all" ] && patch="-a"
54 if [ "$patch" = "-a" ]; then
55 # we are supposed to push all patches, get the last one out of
56 # series
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`
73 # clamp to minimum
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`
80 eidx=`expr $eidx + 1`
81 else
82 # we're supposed to push only up to a patch, make sure the patch is
83 # in the series
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`
98 sidx=`expr $sidx + 1`
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
109 # bail if necessary
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."
114 else
115 die "To force apply this patch, use 'guilt push -f'"
117 done