guilt-applied: added -c to list the commit hash for the patch
[guilt.git] / guilt-pop
blobb0e7ab0a6f05dd22ec683c2fd58d552c08612200
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 eidx=0
22 elif [ -z "$patch" ]; then
23 # we are supposed to pop only the current patch on the stack
25 sidx=`wc -l < $applied`
26 eidx=`expr $sidx - 1`
27 else
28 # we're supposed to pop only up to a patch, make sure the patch is
29 # in the series
31 eidx=`cat $applied | grep -ne "^[0-9a-f]\{40\}:$patch\$" | cut -d: -f 1`
32 if [ -z "$eidx" ]; then
33 echo "Patch $patch is not in the series/is not applied" >&2
34 exit 1
37 eidx=`expr $eidx - 1`
38 sidx=`wc -l < $applied`
41 # make sure that there are no unapplied changes
42 if ! must_commit_first; then
43 echo "Uncommited changes detected. Refresh first." >&2
44 exit 1
47 l=`awk "BEGIN{n=0}(n==$eidx){print \\$0; exit}{n=n+1}END{}" < $applied`
49 pop_many_patches `echo $l | cut -d: -f1`^ `expr $sidx - $eidx`
51 p=`get_top`
52 [ ! -z "$p" ] && echo "Now at $p." || echo "All patches popped."