diff options
Diffstat (limited to 'scripts/send-pull-request')
-rwxr-xr-x | scripts/send-pull-request | 108 |
1 files changed, 21 insertions, 87 deletions
diff --git a/scripts/send-pull-request b/scripts/send-pull-request index 76dd7a2d91..d265c474c0 100755 --- a/scripts/send-pull-request +++ b/scripts/send-pull-request | |||
@@ -1,15 +1,9 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | AUTO=0 | 2 | AUTO=0 |
3 | 3 | ||
4 | # Check env for any default settings, command line options will override these. | ||
5 | if [ -z "$PULL_MTA" ]; then | ||
6 | PULL_MTA="sendmail" | ||
7 | fi | ||
8 | |||
9 | # Prevent environment leakage to these vars. | 4 | # Prevent environment leakage to these vars. |
10 | unset TO | 5 | unset TO |
11 | unset CC | 6 | unset CC |
12 | # allow the user to set FROM in the environment | ||
13 | 7 | ||
14 | usage() | 8 | usage() |
15 | { | 9 | { |
@@ -18,10 +12,6 @@ Usage: $(basename $0) [-h] [-a] [[-t email]...] -p pull-dir | |||
18 | -t email Explicitly add email to the recipients | 12 | -t email Explicitly add email to the recipients |
19 | -a Automatically harvest recipients from "*-by: email" lines | 13 | -a Automatically harvest recipients from "*-by: email" lines |
20 | in the patches in the pull-dir | 14 | in the patches in the pull-dir |
21 | -f Specify a FROM address, you can also use the FROM environment | ||
22 | variable. If you do not specify one, it will try to use the one | ||
23 | from your git config. This is ignored if -g is used. | ||
24 | -g Use git-send-email to send mail instead of sendmail | ||
25 | -p pull-dir Directory containing summary and patch files | 15 | -p pull-dir Directory containing summary and patch files |
26 | EOM | 16 | EOM |
27 | } | 17 | } |
@@ -49,17 +39,11 @@ harvest_recipients() | |||
49 | 39 | ||
50 | 40 | ||
51 | # Parse and verify arguments | 41 | # Parse and verify arguments |
52 | while getopts "af:ghp:t:" OPT; do | 42 | while getopts "ahp:t:" OPT; do |
53 | case $OPT in | 43 | case $OPT in |
54 | a) | 44 | a) |
55 | AUTO=1 | 45 | AUTO=1 |
56 | ;; | 46 | ;; |
57 | f) | ||
58 | FROM="$OPTARG" | ||
59 | ;; | ||
60 | g) | ||
61 | PULL_MTA="git" | ||
62 | ;; | ||
63 | h) | 47 | h) |
64 | usage | 48 | usage |
65 | exit 0 | 49 | exit 0 |
@@ -109,29 +93,14 @@ if [ $AUTO -eq 1 ]; then | |||
109 | harvest_recipients CC "^.*-[Bb][Yy]: *" | 93 | harvest_recipients CC "^.*-[Bb][Yy]: *" |
110 | fi | 94 | fi |
111 | 95 | ||
112 | case "$PULL_MTA" in | 96 | AUTO_TO="$(git config sendemail.to)" |
113 | git) | 97 | if [ -n "$AUTO_TO" ]; then |
114 | FROM="$(git config sendemail.from)" | 98 | if [ -n "$TO" ]; then |
115 | AUTO_TO="$(git config sendemail.to)" | 99 | TO="$TO,$AUTO_TO" |
116 | if [ -n "$AUTO_TO" ]; then | 100 | else |
117 | if [ -n "$TO" ]; then | 101 | TO="$AUTO_TO" |
118 | TO="$TO,$AUTO_TO" | ||
119 | else | ||
120 | TO="$AUTO_TO" | ||
121 | fi | ||
122 | fi | 102 | fi |
123 | ;; | 103 | fi |
124 | sendmail) | ||
125 | if [ -z "$FROM" ]; then | ||
126 | FROM="$(git config user.name) <$(git config user.email)>" | ||
127 | if [ -z "$FROM" ]; then | ||
128 | echo "ERROR: unable to determine a FROM address" | ||
129 | usage | ||
130 | exit 1 | ||
131 | fi | ||
132 | fi | ||
133 | ;; | ||
134 | esac | ||
135 | 104 | ||
136 | if [ -z "$TO" ] && [ -z "$CC" ]; then | 105 | if [ -z "$TO" ] && [ -z "$CC" ]; then |
137 | echo "ERROR: you have not specified any recipients." | 106 | echo "ERROR: you have not specified any recipients." |
@@ -145,10 +114,7 @@ cat <<EOM | |||
145 | The following patches: | 114 | The following patches: |
146 | $(for PATCH in $PDIR/*.patch; do echo " $PATCH"; done) | 115 | $(for PATCH in $PDIR/*.patch; do echo " $PATCH"; done) |
147 | 116 | ||
148 | will be sent with the following headers: | 117 | will now be sent via the git send-email command. |
149 | From: $FROM | ||
150 | To: $TO | ||
151 | CC: $CC | ||
152 | 118 | ||
153 | EOM | 119 | EOM |
154 | echo "Continue? [y/N] " | 120 | echo "Continue? [y/N] " |
@@ -156,52 +122,20 @@ read cont | |||
156 | 122 | ||
157 | if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then | 123 | if [ "$cont" == "y" ] || [ "$cont" == "Y" ]; then |
158 | ERROR=0 | 124 | ERROR=0 |
159 | case "$PULL_MTA" in | 125 | export IFS=$',' |
160 | git) | 126 | GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done) |
161 | export IFS=$',' | 127 | GIT_CC=$(for R in $CC; do echo -n "--cc='$R' "; done) |
162 | GIT_TO=$(for R in $TO; do echo -n "--to='$R' "; done) | 128 | unset IFS |
163 | GIT_CC=$(for R in $CC; do echo -n "--cc='$R' "; done) | 129 | for PATCH in $PDIR/*patch; do |
164 | unset IFS | 130 | # We harvest the emails manually, so force git not to. |
165 | for PATCH in $PDIR/*patch; do | 131 | eval "git send-email $GIT_TO $GIT_CC --no-chain-reply-to --suppress-cc=all $PATCH" |
166 | # We harvest the emails manually, so force git not to. | 132 | if [ $? -eq 1 ]; then |
167 | eval "git send-email $GIT_TO $GIT_CC --no-chain-reply-to --suppress-cc=all $PATCH" | 133 | ERROR=1 |
168 | if [ $? -eq 1 ]; then | 134 | fi |
169 | ERROR=1 | 135 | done |
170 | fi | ||
171 | done | ||
172 | ;; | ||
173 | sendmail) | ||
174 | for PATCH in $PDIR/*patch; do | ||
175 | # Insert To and CC headers via formail to keep them separate and | ||
176 | # appending them to the sendmail command as -- $TO $CC has | ||
177 | # proven to be an exercise in futility. | ||
178 | # | ||
179 | # Clear the From header, leaving it up to sendmail to insert an | ||
180 | # appropriate one. Insert the original sender (per git) into the | ||
181 | # body of the message. | ||
182 | # | ||
183 | # Use tail to remove the email envelope from git or formail as | ||
184 | # msmtp (sendmail) would choke on them. | ||
185 | # | ||
186 | # Modify the patch date for sequential delivery, but retain the | ||
187 | # original date as "Old-Date". | ||
188 | DATE=$(date +"%a, %d %b %Y %k:%M:%S %z") | ||
189 | GIT_FROM=$(cat $PATCH | formail -X "From:") | ||
190 | cat $PATCH | formail -I "To: $TO" -I "CC: $CC" -I "From: $FROM" -i "Date: $DATE" | sed "0,/^$/s/^$/\n$GIT_FROM\n/" | tail -n +2 | sendmail -t | ||
191 | if [ $? -eq 1 ]; then | ||
192 | ERROR=1 | ||
193 | fi | ||
194 | done | ||
195 | ;; | ||
196 | *) | ||
197 | echo "ERROR: unknown MTA: $PULL_MTA" | ||
198 | usage | ||
199 | exit 1 | ||
200 | ;; | ||
201 | esac | ||
202 | 136 | ||
203 | if [ $ERROR -eq 1 ]; then | 137 | if [ $ERROR -eq 1 ]; then |
204 | echo "ERROR: Failed to send one or more messages. Check your MTA log for details." | 138 | echo "ERROR: Failed to send one or more messages." |
205 | fi | 139 | fi |
206 | else | 140 | else |
207 | echo "Send aborted." | 141 | echo "Send aborted." |