Documentation/TODO: Mark guilt-rm as done
[guilt.git] / guilt-pop
blob577350c2e0584870886dd94f9719204212c8fee8
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 source "`dirname $0`/guilt"
8 USAGE="$USAGE [-a | --all | <patchname>]"
10 if [ $# -gt 1 ]; then
11 print_usage
12 exit 1
15 patch="$1"
17 if [ "$patch" = "--all" -o "$patch" = "-a" ]; then
18 # we are supposed to pop all patches
20 sidx=`wc -l < $applied`
21 sidx=`expr $sidx - 1`
22 eidx=0
23 elif [ -z "$patch" ]; then
24 # we are supposed to pop only the current patch on the stack
26 sidx=`wc -l < $applied`
27 sidx=`expr $sidx - 1`
28 eidx=$sidx
29 else
30 # we're supposed to pop only up to a patch, make sure the patch is
31 # in the series
33 eidx=`cat $applied | grep -ne "^[0-9a-f]\{40\}:$patch\$" | cut -d: -f 1`
34 if [ -z "$eidx" ]; then
35 echo "Patch $patch is not in the series/is not applied" >&2
36 exit 1
39 eidx=`expr $eidx - 1`
40 sidx=`wc -l < $applied`
41 sidx=`expr $sidx - 1`
44 # make sure that there are no unapplied changes
45 if ! must_commit_first; then
46 echo "Uncommited changes detected. Refresh first." >&2
47 exit 1
50 idx=`get_series | wc -l`
51 for p in `get_series | tac`; do
52 idx=`expr $idx - 1`
53 [ $idx -gt $sidx ] && continue
54 [ $idx -lt $eidx ] && break
56 echo "Popping patch...`tail -1 < $applied | cut -d: -f 2-`"
58 pop_patch
59 done
61 p=`get_top`
62 [ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped."