regression: add tests for guilt-header
[guilt/mob.git] / guilt-new
blob6ec0e0347983d7b58e62402816b5b51745c04f59
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006, 2007
6 USAGE="[-f] [-s] [-e|-m message] <patchname>"
7 . `dirname $0`/guilt
9 if [ $# -lt 1 ] || [ $# -gt 4 ]; then
10 usage
13 while [ $# -gt 0 ] ; do
14 case "$1" in
15 -f)
16 force=t
18 -s)
19 signoff=t
21 -e)
22 edit=t
24 if [ ! -z "$msg" ]; then
25 usage
28 -m)
29 msg="$2"
30 shift
32 if [ ! -z "$edit" ]; then
33 usage
37 if [ ! -z "$patch" ]; then
38 usage
40 patch="$1"
42 esac
43 shift
44 done
46 if [ -z "$patch" ]; then
47 die "You must specify a patch name"
50 if [ -f "$GUILT_DIR/$branch/$patch" ]; then
51 die "patch '$patch' already exist"
54 iidx=`wc -l < "$applied"`
56 # make sure that there are no unapplied changes
57 if [ -z "$force" ] && ! must_commit_first; then
58 die "Uncommited changes detected. Refresh first."
61 if ! valid_patchname "$patch"; then
62 echo "Patchname is invalid." >&2
63 die "it cannot begin with '/', './' or '../', or contain /./ or /../"
66 # create any directories as needed
67 mkdir_dir=`dirname "$GUILT_DIR/$branch/$patch"`
68 [ "$mkdir_dir" != "$GUILT_DIR/$branch" ] && mkdir -p "$mkdir_dir"
70 # create the file with the right contents
72 # did we get a message with -m ?
73 [ ! -z "$msg" ] && printf "$msg\n\n"
75 # add a sign-off-by (-s)
76 [ "$signoff" = "t" ] && printf "Signed-off-by: `git var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`\n\n"
77 ) >> "$GUILT_DIR/$branch/$patch"
79 # edit -e ?
80 [ "$edit" = "t" ] && $editor "$GUILT_DIR/$branch/$patch"
82 if [ ! -z "$force" ]; then
84 cd "$TOP_DIR"
85 git diff HEAD >> "$GUILT_DIR/$branch/$patch"
86 git reset --hard HEAD > /dev/null
90 # insert the patch name into the series file
91 series_insert_patch "$patch"
93 # apply the patch
94 push_patch "$patch"