docs: Commands should be on a separate line
[guilt.git] / guilt-pop
blob1ac1d123b60f80cca6b9875b053f95714866244b
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[-a | --all | <patchname>]"
7 . guilt
9 if [ $# -gt 1 ]; then
10 usage
13 patch="$1"
15 if [ "$patch" = "--all" -o "$patch" = "-a" ]; then
16 # we are supposed to pop all patches
18 sidx=`wc -l < $applied`
19 eidx=0
20 elif [ -z "$patch" ]; then
21 # we are supposed to pop only the current patch on the stack
23 sidx=`wc -l < $applied`
24 eidx=`expr $sidx - 1`
25 else
26 # we're supposed to pop only up to a patch, make sure the patch is
27 # in the series
29 eidx=`cat $applied | grep -ne "^[0-9a-f]\{40\}:$patch\$" | cut -d: -f 1`
30 if [ -z "$eidx" ]; then
31 die "Patch $patch is not in the series/is not applied"
34 eidx=`expr $eidx - 1`
35 sidx=`wc -l < $applied`
38 # make sure that there are no unapplied changes
39 if ! must_commit_first; then
40 die "Uncommited changes detected. Refresh first."
43 l=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied`
45 pop_many_patches `echo $l | cut -d: -f1`^ `expr $sidx - $eidx`
47 p=`get_top`
48 [ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped."