repair: new command to repair repository state
[guilt.git] / guilt-patchbomb
blob5fc6cab0aa861d74715f5726b7846dea471a33d6
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 echo -n "Are these what you want to send? [Y/n] "
38 read n
39 if [ "$n" = "n" ] || [ "$n" = "N" ]; then
40 die "Aborting..."
43 dir=/tmp/patches-$RANDOM/
44 if [ -e $dir ]; then
45 die "Conspiracy uncovered: Temporary dir '$dir' already exists"
47 echo "Using '$dir' as temporary directory"
49 git-format-patch -o $dir -n -s "$r"
51 # get the to/cc addresses
52 echo -n "Enter all the To: email addresses (separated by space): "
53 read rawto
54 echo -n "Enter all the Cc: email addresses (separated by space): "
55 read rawcc
57 # convert list of email addresses to command line options
58 to_opts=""
59 for rt in $rawto; do
60 to_opts="$to_opts --to $rt"
61 done
62 for rc in $rawcc; do
63 to_opts="$to_opts --cc $rc"
64 done
66 opts=""
68 # more than 1 commit
69 if [ `git-rev-list "$r" | wc -l` -gt 1 ]; then
70 opts="$opts --no-chain-reply-to --compose"
72 opts="$opts $to_opts"
74 ls "$dir" | while read n; do
75 fulln="$dir/$n"
77 do_get_full_header "$fulln" | awk '
78 BEGIN{p=0}
79 /^$/{p=1}
80 /^[Cc][Cc]: / && (p==1){print substr($0, 5)}
81 ' | sed -n -e '
82 1 h
83 2,$ H
84 $ {
86 s/\n/, /g
88 }' > "$TMP_FILE"
89 if [ -s "$TMP_FILE" ]; then
90 head -1 "$fulln" > "$fulln~"
91 echo -n "Cc: " >> "$fulln~"
92 cat "$TMP_FILE" >> "$fulln~"
93 tail -n +2 "$fulln" >> "$fulln~"
94 mv "$fulln~" "$fulln"
95 echo "${n:0:4}: Including Cc from patch description"
96 rm -f "$TMP_FILE"
98 done
100 # last possible point to abort!
101 echo -n "Proceed with patchbomb (this is the last chance to abort)? [y/N] "
102 read n
103 if [ "$n" != "y" ] && [ "$n" != "Y" ]; then
104 die "Aborting..."
107 # ...and off they go.
108 cmd="git-send-email"
109 if [ ! -z "$do_not_send" ]; then
110 echo "-n passed: not sending, command that would be executed:" >&2
111 cmd="echo git-send-email"
114 if [ -z "$reply_to" ]; then
115 $cmd $opts $dir
116 else
117 $cmd --in-reply-to "$reply_to" $opts $dir
120 # cleanup?
121 echo -n "Delete temporary directory? [Y/n] "
122 read n
124 [ "$n" = "n" ] || [ "$n" = "N" ] && exit 0
125 rm -rf $dir