guilt: Working around missing touch -d on Darwin.
[guilt/mob.git] / guilt-patchbomb
blob81820c6efea0976dd47f780aa3e2e1927deae4ea
1 #!/bin/sh
3 # Copyright (c) Josef "Jeff" Sipek, 2007
6 DO_NOT_CHECK_BRANCH_EXISTENCE=1
8 USAGE="[-n] [-s] [--in-reply-to <msgid>] [--git] [--subject-prefix <prefix>] [<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 -s)
19 no_sign_off=t
21 --subject-prefix)
22 subject_prefix="$2"
23 shift
25 --in-reply-to)
26 reply_to="$2"
27 shift
29 --git)
30 gitdiff=t
33 break
35 esac
36 shift
37 done
39 r=`munge_hash_range "$1"`
40 if [ $? -ne 0 ]; then
41 usage
44 # display the list of commits to be sent as patches
45 git log --pretty=oneline "$r" | cut -c 1-8,41- | $pager
47 _disp "Are these what you want to send? [Y/n] "
48 read n
49 if [ "$n" = "n" ] || [ "$n" = "N" ]; then
50 die "Aborting..."
53 dir=`get_tmp_file patchbomb -d`
54 disp "Using '$dir' as temporary directory"
56 # more than one patch?
57 if [ `git rev-list "$r" | wc -l` -gt 1 ]; then
58 format_opts="-n" # include "n/m" in the subject
59 send_opts="--no-chain-reply-to --compose" # compose
62 [ ! -z "$gitdiff" ] && format_opts="$format_opts -C -M --find-copies-harder"
63 [ -z "$no_sign_off" ] && format_opts="$format_opts -s"
65 if [ -z "$subject_prefix" ]; then
66 git format-patch $format_opts -o $dir "$r"
67 else
68 git format-patch $format_opts --subject-prefix="$subject_prefix" -o $dir "$r"
71 # get the to/cc addresses
72 _disp "Enter all the To: email addresses (separated by space): "
73 read rawto
74 _disp "Enter all the Cc: email addresses (separated by space): "
75 read rawcc
77 # convert list of email addresses to command line options
78 to_opts=""
79 for rt in $rawto; do
80 to_opts="$to_opts --to $rt"
81 done
82 for rc in $rawcc; do
83 to_opts="$to_opts --cc $rc"
84 done
86 opts="$send_opts $to_opts"
88 # last possible point to abort!
89 _disp "Proceed with patchbomb (this is the last chance to abort)? [y/N] "
90 read n
91 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
92 die "Aborting..."
95 # ...and off they go.
96 cmd="git send-email"
97 if [ ! -z "$do_not_send" ]; then
98 disp "-n passed: not sending, command that would be executed:" >&2
99 cmd="echo git send-email"
102 if [ -z "$reply_to" ]; then
103 $cmd $opts $dir
104 else
105 $cmd --in-reply-to "$reply_to" $opts $dir
108 # cleanup?
109 _disp "Delete temporary directory? [Y/n] "
110 read n
112 [ "$n" = "n" ] || [ "$n" = "N" ] && exit 0
113 rm -rf $dir