Guilt v0.32-rc2
[guilt/mob.git] / guilt-new
blobe539b5b3428e2b7a4222200eafc9168dde619f9a
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 disp "Patchname is invalid." >&2
63 die "it cannot begin with '/', './' or '../', or contain /./, /../, or whitespace"
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" ] && git_editor "$GUILT_DIR/$branch/$patch"
82 if [ ! -z "$force" ]; then
84 cd_to_toplevel
85 git diff HEAD >> "$GUILT_DIR/$branch/$patch"
89 # insert the patch name into the series file
90 series_insert_patch "$patch"
92 # apply the patch
93 echo "$patch" >> $applied
94 commit "$patch" HEAD