merge
[guilt.git] / gq-pop
blobcadcad6c6db0fa89546150d983d332186d4a3e98
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006
6 source "`dirname $0`/gq.lib"
8 export GIT_DIR=`find_git_dir`
9 GQ_DIR="$GIT_DIR/patches"
11 branch=`get_branch_verify`
12 series="$GQ_DIR/$branch/series"
13 applied="$GQ_DIR/$branch/status"
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 "^$patch\$" | cut -d: -f1`
34 if [ -z "$eidx" ]; then
35 echo "Patch $patch is not in the series/is not applied"
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."
47 exit 1
50 idx=`wc -l < $series`
51 for p in `cat $series | tac`; do
52 idx=`expr $idx - 1`
53 [ $idx -gt $sidx ] && continue
54 [ $idx -lt $eidx ] && break
56 echo "Popping patch...$p"
58 pop_patch
59 done
61 p=`get_top`
62 [ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped."