patchbomb: added --git option
[guilt.git] / guilt-patchbomb
blob6497e076e62d5447443bf87865367e1cb5720141
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 DO_NOT_CHECK_BRANCH_EXISTENCE=1
8 USAGE="[-n] [--in-reply-to <msgid>] [--git] [<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
22 --git)
23 gitdiff=t
26 break
28 esac
29 shift
30 done
32 r=`munge_hash_range "$1"`
33 if [ $? -ne 0 ]; then
34 usage
37 # display the list of commits to be sent as patches
38 git log --pretty=oneline "$r" | cut -c 1-8,41- | $pager
40 _disp "Are these what you want to send? [Y/n] "
41 read n
42 if [ "$n" = "n" ] || [ "$n" = "N" ]; then
43 die "Aborting..."
46 dir=`get_tmp_file patchbomb -d`
47 disp "Using '$dir' as temporary directory"
49 # more than one patch?
50 if [ `git rev-list "$r" | wc -l` -gt 1 ]; then
51 format_opts="-n" # include "n/m" in the subject
52 send_opts="--no-chain-reply-to --compose" # compose
55 [ ! -z "$gitdiff" ] && format_opts="$format_opts -C -M --find-copies-harder"
57 git format-patch $format_opts -o $dir -s "$r"
59 # get the to/cc addresses
60 _disp "Enter all the To: email addresses (separated by space): "
61 read rawto
62 _disp "Enter all the Cc: email addresses (separated by space): "
63 read rawcc
65 # convert list of email addresses to command line options
66 to_opts=""
67 for rt in $rawto; do
68 to_opts="$to_opts --to $rt"
69 done
70 for rc in $rawcc; do
71 to_opts="$to_opts --cc $rc"
72 done
74 opts="$send_opts $to_opts"
76 # last possible point to abort!
77 _disp "Proceed with patchbomb (this is the last chance to abort)? [y/N] "
78 read n
79 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
80 die "Aborting..."
83 # ...and off they go.
84 cmd="git send-email"
85 if [ ! -z "$do_not_send" ]; then
86 disp "-n passed: not sending, command that would be executed:" >&2
87 cmd="echo git send-email"
90 if [ -z "$reply_to" ]; then
91 $cmd $opts $dir
92 else
93 $cmd --in-reply-to "$reply_to" $opts $dir
96 # cleanup?
97 _disp "Delete temporary directory? [Y/n] "
98 read n
100 [ "$n" = "n" ] || [ "$n" = "N" ] && exit 0
101 rm -rf $dir