new: added -e to edit the patch description interactively
[guilt.git] / guilt-new
blob6887dec8af7e75b9f5f703437544699e59e61c98
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 source "`dirname $0`/guilt"
8 USAGE="$USAGE [-s] [-e|-m message] <patchname>"
10 if [ $# -lt 1 -o $# -gt 4 ]; then
11 print_usage
12 exit 1
15 while [ $# -gt 0 ] ; do
16 case "$1" in
17 -s)
18 signoff=t
20 -e)
21 edit=t
23 if [ ! -z "$msg" ]; then
24 print_usage
25 exit 1
28 -m)
29 msg="$2"
30 shift
32 if [ ! -z "$edit" ]; then
33 print_usage
34 exit 1
38 if [ ! -z "$patch" ]; then
39 print_usage
40 exit 1
42 patch="$1"
44 esac
45 shift
46 done
48 if [ -z "$patch" ]; then
49 print_usage
50 echo "You must specify a patch name"
51 exit 1
54 iidx=`wc -l < $applied`
56 # make sure that there are no unapplied changes
57 if ! must_commit_first; then
58 echo "Uncommited changes detected. Refresh first."
59 exit 1
62 # create any directories as needed
63 [ "`dirname $patch`" != "." ] && mkdir -p `dirname $GUILT_DIR/$branch/$patch`
65 # create the file with the right contents
67 # did we get a message with -m ?
68 [ ! -z "$msg" ] && echo "$msg"
70 # add a sign-off-by (-s)
71 [ "$signoff" = "t" ] && echo -e "\nSigned-off-by: `git-var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`"
72 ) >> $GUILT_DIR/$branch/$patch
74 # edit -e ?
75 [ "$edit" = "t" ] && $editor $GUILT_DIR/$branch/$patch
77 top=`get_top`
79 if [ ! -z "$top" ]; then
80 sed -i -e "s,^$top\$,$top\n$patch," $series
81 else
82 echo "$patch" > $series.tmp
83 cat $series >> $series.tmp
84 mv $series.tmp $series
87 # apply the patch
88 push_patch $patch