Ignore empty/commented series lines
[gq.git] / gq-pop
blob9a5f6c331924a6cc59bb3d4ddc5ac10f21509369
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006
6 source "`dirname $0`/gq.lib"
8 patch="$1"
10 if [ "$patch" = "--all" -o "$patch" = "-a" ]; then
11 # we are supposed to pop all patches
13 sidx=`wc -l < $applied`
14 sidx=`expr $sidx - 1`
15 eidx=0
16 elif [ -z "$patch" ]; then
17 # we are supposed to pop only the current patch on the stack
19 sidx=`wc -l < $applied`
20 sidx=`expr $sidx - 1`
21 eidx=$sidx
22 else
23 # we're supposed to pop only up to a patch, make sure the patch is
24 # in the series
26 eidx=`cat $applied | grep -ne "^$patch\$" | cut -d: -f1`
27 if [ -z "$eidx" ]; then
28 echo "Patch $patch is not in the series/is not applied"
29 exit 1
32 eidx=`expr $eidx - 1`
33 sidx=`wc -l < $applied`
34 sidx=`expr $sidx - 1`
37 # make sure that there are no unapplied changes
38 if ! must_commit_first; then
39 echo "Uncommited changes detected. Refresh first."
40 exit 1
43 idx=`get_series | wc -l`
44 for p in `get_series | tac`; do
45 idx=`expr $idx - 1`
46 [ $idx -gt $sidx ] && continue
47 [ $idx -lt $eidx ] && break
49 echo "Popping patch...$p"
51 pop_patch
52 done
54 p=`get_top`
55 [ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped."