Skip to content

Commit cb8a9bd

Browse files
bonzinigitster
authored andcommitted
Test cccmd in t9001-send-email.sh and fix some bugs
For another patch series I'm working on I needed some tests for the cc-cmd feature of git-send-email. This patch adds 3 tests for the feature and for the possibility to specify --suppress-cc multiple times, and fixes two bugs. The first bug is that the --suppress-cc option for `cccmd' was misspelled as `ccmd' in the code. The second bug, which is actually found only with my other series, is that the argument to the cccmd is never quoted, so the cccmd would fail with patch file names containing a space. A third bug I fix (in the docs) is that the bodycc argument was actually spelled ccbody in the documentation and bash completion. Signed-off-by: Paolo Bonzini <[email protected]> Cc: Markus Heidelberg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f4fa9c commit cb8a9bd

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed

Documentation/git-send-email.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ Automating
193193
- 'self' will avoid including the sender
194194
- 'cc' will avoid including anyone mentioned in Cc lines in the patch header
195195
except for self (use 'self' for that).
196-
- 'ccbody' will avoid including anyone mentioned in Cc lines in the
196+
- 'bodycc' will avoid including anyone mentioned in Cc lines in the
197197
patch body (commit message) except for self (use 'self' for that).
198198
- 'sob' will avoid including anyone mentioned in Signed-off-by lines except
199199
for self (use 'self' for that).
200200
- 'cccmd' will avoid running the --cc-cmd.
201-
- 'body' is equivalent to 'sob' + 'ccbody'
201+
- 'body' is equivalent to 'sob' + 'bodycc'
202202
- 'all' will suppress all auto cc values.
203203
--
204204
+

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ _git_rebase ()
12991299
}
13001300

13011301
__git_send_email_confirm_options="always never auto cc compose"
1302-
__git_send_email_suppresscc_options="author self cc ccbody sob cccmd body all"
1302+
__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
13031303

13041304
_git_send_email ()
13051305
{

git-send-email.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ sub read_config {
334334
}
335335

336336
if ($suppress_cc{'all'}) {
337-
foreach my $entry (qw (ccmd cc author self sob body bodycc)) {
337+
foreach my $entry (qw (cccmd cc author self sob body bodycc)) {
338338
$suppress_cc{$entry} = 1;
339339
}
340340
delete $suppress_cc{'all'};
@@ -1104,7 +1104,7 @@ sub send_message
11041104
close F;
11051105

11061106
if (defined $cc_cmd && !$suppress_cc{'cccmd'}) {
1107-
open(F, "$cc_cmd $t |")
1107+
open(F, "$cc_cmd \Q$t\E |")
11081108
or die "(cc-cmd) Could not execute '$cc_cmd'";
11091109
while(<F>) {
11101110
my $c = $_;

t/t9001-send-email.sh

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,22 @@ test_expect_success 'Prompting works' '
148148
grep "^To: [email protected]$" msgtxt1
149149
'
150150

151+
test_expect_success 'cccmd works' '
152+
clean_fake_sendmail &&
153+
cp $patches cccmd.patch &&
154+
echo [email protected] >>cccmd.patch &&
155+
echo sed -n s/^cccmd--//p \"\$1\" > cccmd-sed &&
156+
chmod +x cccmd-sed &&
157+
git send-email \
158+
--from="Example <[email protected]>" \
159+
160+
--cc-cmd=./cccmd-sed \
161+
--smtp-server="$(pwd)/fake.sendmail" \
162+
cccmd.patch \
163+
&&
164+
grep ^Cc:.*[email protected] msgtxt1
165+
'
166+
151167
z8=zzzzzzzz
152168
z64=$z8$z8$z8$z8$z8$z8$z8$z8
153169
z512=$z64$z64$z64$z64$z64$z64$z64$z64
@@ -274,16 +290,16 @@ EOF
274290
test_suppression () {
275291
git send-email \
276292
--dry-run \
277-
--suppress-cc=$1 \
293+
--suppress-cc=$1 ${2+"--suppress-cc=$2"} \
278294
--from="Example <[email protected]>" \
279295
280296
--smtp-server relay.example.com \
281297
$patches |
282298
sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
283299
-e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
284300
-e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
285-
>actual-suppress-$1 &&
286-
test_cmp expected-suppress-$1 actual-suppress-$1
301+
>actual-suppress-$1${2+"-$2"} &&
302+
test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
287303
}
288304

289305
test_expect_success 'sendemail.cc set' '
@@ -316,6 +332,34 @@ test_expect_success 'sendemail.cc unset' '
316332
test_suppression sob
317333
'
318334

335+
cat >expected-suppress-cccmd <<\EOF
336+
0001-Second.patch
337+
(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>'
338+
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
339+
(mbox) Adding cc: [email protected] from line 'Cc: One <[email protected]>, [email protected]'
340+
(body) Adding cc: C O Mitter <[email protected]> from line 'Signed-off-by: C O Mitter <[email protected]>'
341+
Dry-OK. Log says:
342+
Server: relay.example.com
343+
MAIL FROM:<[email protected]>
344+
345+
From: Example <[email protected]>
346+
347+
348+
Subject: [PATCH 1/1] Second.
349+
Date: DATE-STRING
350+
Message-Id: MESSAGE-ID-STRING
351+
X-Mailer: X-MAILER-STRING
352+
353+
Result: OK
354+
EOF
355+
356+
test_expect_success 'sendemail.cccmd' '
357+
echo echo [email protected] > cccmd &&
358+
chmod +x cccmd &&
359+
git config sendemail.cccmd ./cccmd &&
360+
test_suppression cccmd
361+
'
362+
319363
cat >expected-suppress-all <<\EOF
320364
0001-Second.patch
321365
Dry-OK. Log says:
@@ -341,13 +385,14 @@ cat >expected-suppress-body <<\EOF
341385
(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>'
342386
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
343387
(mbox) Adding cc: [email protected] from line 'Cc: One <[email protected]>, [email protected]'
388+
(cc-cmd) Adding cc: [email protected] from: './cccmd'
344389
Dry-OK. Log says:
345390
Server: relay.example.com
346391
MAIL FROM:<[email protected]>
347-
392+
348393
From: Example <[email protected]>
349394
350-
395+
351396
Subject: [PATCH 1/1] Second.
352397
Date: DATE-STRING
353398
Message-Id: MESSAGE-ID-STRING
@@ -360,6 +405,30 @@ test_expect_success '--suppress-cc=body' '
360405
test_suppression body
361406
'
362407

408+
cat >expected-suppress-body-cccmd <<\EOF
409+
0001-Second.patch
410+
(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>'
411+
(mbox) Adding cc: One <[email protected]> from line 'Cc: One <[email protected]>, [email protected]'
412+
(mbox) Adding cc: [email protected] from line 'Cc: One <[email protected]>, [email protected]'
413+
Dry-OK. Log says:
414+
Server: relay.example.com
415+
MAIL FROM:<[email protected]>
416+
417+
From: Example <[email protected]>
418+
419+
420+
Subject: [PATCH 1/1] Second.
421+
Date: DATE-STRING
422+
Message-Id: MESSAGE-ID-STRING
423+
X-Mailer: X-MAILER-STRING
424+
425+
Result: OK
426+
EOF
427+
428+
test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
429+
test_suppression body cccmd
430+
'
431+
363432
cat >expected-suppress-sob <<\EOF
364433
0001-Second.patch
365434
(mbox) Adding cc: A <[email protected]> from line 'From: A <[email protected]>'
@@ -381,6 +450,7 @@ Result: OK
381450
EOF
382451

383452
test_expect_success '--suppress-cc=sob' '
453+
git config --unset sendemail.cccmd
384454
test_suppression sob
385455
'
386456

0 commit comments

Comments
 (0)