Documentation: clean up the makefile
[guilt.git] / guilt-commit
blob6db8efabf5e3003eabf09f089262f1b9a4ae50f0
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2008-2013
6 USAGE="-n <num> | -a | --all"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 case "$1" in
15 -a|--all)
16 [ $# -gt 1 ] && usage
17 pat_commit="1,\$p"
18 pat_keep=""
20 -n)
21 [ $# -gt 2 ] && usage
22 [ "$2" -lt 0 ] && die "Must specify a number of patches to commit"
23 [ "$2" -eq 0 ] && exit 0
25 pat_commit="1,$2p"
26 pat_keep="`expr "$2" + 1`,\$p"
29 usage
31 esac
33 # if nothing's applied, exit
34 [ `wc -l < "$applied"` -eq 0 ] && exit 0
36 # remove patch refs for what's being committed, and update series
37 sed -n -e "${pat_commit}" "$applied" | while read pname; do
38 # update the base branch to the last committed patch
39 $old_style_prefix || git update-ref refs/heads/$branch \
40 refs/patches/$branch/$pname
42 series_remove_patch "$pname"
43 echo "$pname" | remove_patch_refs
44 done
46 # update $applied to include only the patches we're keeping
47 sed -n -e "${pat_keep}" "$applied" > "$applied.tmp"
48 mv "$applied.tmp" "$applied"
50 # if we removed the last patch, switch back to the base branch
51 if [ `wc -l < "$applied"` -eq 0 ] && [ "`git symbolic-ref HEAD`" = "refs/heads/$GUILT_PREFIX$branch" ] && ! $old_style_prefix
52 then
53 git update-ref refs/heads/$branch refs/heads/$GUILT_PREFIX$branch
54 git symbolic-ref HEAD refs/heads/$branch
55 git update-ref -d refs/heads/$GUILT_PREFIX$branch