Quote variables as frequently as possible to prevent whitespace problems
[guilt.git] / guilt-new
blob9331683134d66eea69e2ade934e8b455c1c2f9ee
1 #!/bin/bash
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[-s] [-e|-m message] <patchname>"
7 . guilt
9 if [ $# -lt 1 -o $# -gt 4 ]; then
10 usage
13 while [ $# -gt 0 ] ; do
14 case "$1" in
15 -s)
16 signoff=t
18 -e)
19 edit=t
21 if [ ! -z "$msg" ]; then
22 usage
25 -m)
26 msg="$2"
27 shift
29 if [ ! -z "$edit" ]; then
30 usage
34 if [ ! -z "$patch" ]; then
35 usage
37 patch="$1"
39 esac
40 shift
41 done
43 if [ -z "$patch" ]; then
44 die "You must specify a patch name"
47 if [ -f "$GUILT_DIR/$branch/$patch" ]; then
48 die "patch '$patch' already exist"
51 iidx=`wc -l < "$applied"`
53 # make sure that there are no unapplied changes
54 if ! must_commit_first; then
55 die "Uncommited changes detected. Refresh first."
58 if ! valid_patchname "$patch"; then
59 echo "Patchname is invalid." >&2
60 die "it cannot begin with '/', './' or '../', or contain /./ or /../"
63 # create any directories as needed
64 mkdir_dir=`dirname "$GUILT_DIR/$branch/$patch"`
65 [ "$mkdir_dir" != "$GUILT_DIR/$branch" ] && mkdir -p "$mkdir_dir"
67 # create the file with the right contents
69 # did we get a message with -m ?
70 [ ! -z "$msg" ] && echo "$msg"
72 # add a sign-off-by (-s)
73 [ "$signoff" = "t" ] && echo -e "\nSigned-off-by: `git-var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`"
74 ) >> "$GUILT_DIR/$branch/$patch"
76 # edit -e ?
77 [ "$edit" = "t" ] && $editor "$GUILT_DIR/$branch/$patch"
79 # insert the patch name into the series file
80 series_insert_patch "$patch"
82 # apply the patch
83 push_patch "$patch"