patchbomb: fix bashism
[guilt.git] / guilt-patchbomb
blob5e545725439da9771d30628f390c7c75b2478edf
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 DO_NOT_CHECK_BRANCH_EXISTENCE=1
8 USAGE="[-n] [--in-reply-to <msgid>] [<hash> | <since>..[<until>] | ..<until>]"
9 . `dirname $0`/guilt
11 TMP_FILE=`get_tmp_file file`
13 while [ $# -gt 0 ]; do
14 case "$1" in
15 -n)
16 do_not_send=t
18 --in-reply-to)
19 reply_to="$2"
20 shift
23 break
25 esac
26 shift
27 done
29 r=`munge_hash_range "$1"`
30 if [ $? -ne 0 ]; then
31 usage
34 # display the list of commits to be sent as patches
35 git log --pretty=oneline "$r" | cut -c 1-8,41- | $pager
37 _disp "Are these what you want to send? [Y/n] "
38 read n
39 if [ "$n" = "n" ] || [ "$n" = "N" ]; then
40 die "Aborting..."
43 dir=`get_tmp_file patchbomb -d`
44 disp "Using '$dir' as temporary directory"
46 # more than one patch?
47 if [ `git rev-list "$r" | wc -l` -gt 1 ]; then
48 format_opts="-n" # include "n/m" in the subject
49 send_opts="--no-chain-reply-to --compose" # compose
52 git format-patch $format_opts -o $dir -s "$r"
54 # get the to/cc addresses
55 _disp "Enter all the To: email addresses (separated by space): "
56 read rawto
57 _disp "Enter all the Cc: email addresses (separated by space): "
58 read rawcc
60 # convert list of email addresses to command line options
61 to_opts=""
62 for rt in $rawto; do
63 to_opts="$to_opts --to $rt"
64 done
65 for rc in $rawcc; do
66 to_opts="$to_opts --cc $rc"
67 done
69 opts="$send_opts $to_opts"
71 # last possible point to abort!
72 _disp "Proceed with patchbomb (this is the last chance to abort)? [y/N] "
73 read n
74 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
75 die "Aborting..."
78 # ...and off they go.
79 cmd="git send-email"
80 if [ ! -z "$do_not_send" ]; then
81 disp "-n passed: not sending, command that would be executed:" >&2
82 cmd="echo git send-email"
85 if [ -z "$reply_to" ]; then
86 $cmd $opts $dir
87 else
88 $cmd --in-reply-to "$reply_to" $opts $dir
91 # cleanup?
92 _disp "Delete temporary directory? [Y/n] "
93 read n
95 [ "$n" = "n" ] || [ "$n" = "N" ] && exit 0
96 rm -rf $dir