guilt: remove a useless cat
[guilt.git] / guilt-new
blob0803063355b238c2041015e7f1e4fd2f9d4da7e3
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2006-2011
6 USAGE="[-f] [-s] [-e|-m message] <patchname>"
7 if [ -z "$GUILT_VERSION" ]; then
8 echo "Invoking $GUILT directly is no longer supported." >&2
9 exit 1
12 _main() {
14 if [ $# -lt 1 ] || [ $# -gt 4 ]; then
15 usage
18 while [ $# -gt 0 ] ; do
19 case "$1" in
20 -f)
21 force=t
23 -s)
24 signoff=t
26 -e)
27 edit=t
29 if [ ! -z "$msg" ]; then
30 usage
33 -m)
34 msg="$2"
35 shift
37 if [ ! -z "$edit" ]; then
38 usage
42 if [ ! -z "$patch" ]; then
43 usage
45 patch="$1"
47 esac
48 shift
49 done
51 if [ -z "$patch" ]; then
52 die "You must specify a patch name"
55 if [ -f "$GUILT_DIR/$branch/$patch" ]; then
56 die "patch '$patch' already exist"
59 iidx=`wc -l < "$applied"`
61 # make sure that there are no unapplied changes
62 if [ -z "$force" ] && ! must_commit_first; then
63 die "Uncommited changes detected. Refresh first."
66 if ! valid_patchname "$patch"; then
67 disp "Patchname is invalid." >&2
68 die "it cannot begin with '/', './' or '../', or contain /./, /../, or whitespace"
71 # create any directories as needed
72 mkdir_dir=`dirname "$GUILT_DIR/$branch/$patch"`
73 [ "$mkdir_dir" != "$GUILT_DIR/$branch" ] && mkdir -p "$mkdir_dir"
75 # create the file with the right contents
77 # did we get a message with -m ?
78 [ ! -z "$msg" ] && printf "$msg\n\n"
80 # add a sign-off-by (-s)
81 [ "$signoff" = "t" ] && printf "Signed-off-by: `git var GIT_COMMITTER_IDENT | sed -e 's/>.*/>/'`\n\n"
82 ) >> "$GUILT_DIR/$branch/$patch"
84 # edit -e ?
85 [ "$edit" = "t" ] && git_editor "$GUILT_DIR/$branch/$patch"
87 if [ ! -z "$force" ]; then
89 cd_to_toplevel
90 git diff --binary HEAD >> "$GUILT_DIR/$branch/$patch"
94 # insert the patch name into the series file
95 series_insert_patch "$patch"
97 # apply the patch
98 echo "$patch" >> "$applied"
99 commit "$patch" HEAD