Guilt v0.36-rc1
[guilt.git] / guilt-fold
blobb22ec2c9fa7a5f9ec7cc72cb041942747d0c8462
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006-2013
6 USAGE="[-k] <patchname>"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking `basename "$0"` directly is no longer supported." >&2
9 exit 1
12 _main() {
14 if [ "$1" = "-k" ]; then
15 keep=t
16 shift
19 if [ $# -ne 1 ]; then
20 usage
23 patch="$1"
24 if [ -z "$patch" ]; then
25 die "No patch name supplied."
28 # make sure it is a file
29 if [ ! -f "$GUILT_DIR/$branch/$patch" ]; then
30 die "Patch $patch does not exist."
33 # make sure that there are no unapplied changes
34 if ! must_commit_first; then
35 die "Uncommited changes detected. Refresh first."
38 # make sure it is not applied
39 pline=`cat "$applied" | grep -e "^$patch$"`
40 if [ ! -z "$pline" ]; then
41 die "Patch is applied. Pop the patch first."
44 fold_patch "$patch"
46 # back it up just in case :)
47 [ -z "$keep" ] && mv "$GUILT_DIR/$branch/$patch" "$GUILT_DIR/$branch/$patch~"