Skip to content

Commit f434c08

Browse files
bebarinogitster
authored andcommitted
send-email: add --no-cc, --no-to, and --no-bcc
There's no way to override the sendemail.to, sendemail.cc, and sendemail.bcc config settings. Add options allowing the user to tell git to ignore the config settings and take whatever is on the command line. Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c426003 commit f434c08

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

git-send-email.perl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ sub usage {
4747
4848
Composing:
4949
--from <str> * Email From:
50-
--to <str> * Email To:
51-
--cc <str> * Email Cc:
52-
--bcc <str> * Email Bcc:
50+
--[no-]to <str> * Email To:
51+
--[no-]cc <str> * Email Cc:
52+
--[no-]bcc <str> * Email Bcc:
5353
--subject <str> * Email "Subject:"
5454
--in-reply-to <str> * Email "In-Reply-To:"
5555
--annotate * Review each patch that will be sent in an editor.
@@ -135,7 +135,7 @@ sub format_2822_time {
135135
sub cleanup_compose_files();
136136

137137
# Variables we fill in automatically, or via prompting:
138-
my (@to,@cc,@initial_cc,@bcclist,@xh,
138+
my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
139139
$initial_reply_to,$initial_subject,@files,
140140
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
141141

@@ -261,8 +261,11 @@ sub signal_handler {
261261
"in-reply-to=s" => \$initial_reply_to,
262262
"subject=s" => \$initial_subject,
263263
"to=s" => \@to,
264+
"no-to" => \$no_to,
264265
"cc=s" => \@initial_cc,
266+
"no-cc" => \$no_cc,
265267
"bcc=s" => \@bcclist,
268+
"no-bcc" => \$no_bcc,
266269
"chain-reply-to!" => \$chain_reply_to,
267270
"smtp-server=s" => \$smtp_server,
268271
"smtp-server-port=s" => \$smtp_server_port,
@@ -305,6 +308,9 @@ sub read_config {
305308

306309
foreach my $setting (keys %config_settings) {
307310
my $target = $config_settings{$setting};
311+
next if $setting eq "to" and defined $no_to;
312+
next if $setting eq "cc" and defined $no_cc;
313+
next if $setting eq "bcc" and defined $no_bcc;
308314
if (ref($target) eq "ARRAY") {
309315
unless (@$target) {
310316
my @values = Git::config(@repo, "$prefix.$setting");

t/t9001-send-email.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,4 +852,70 @@ test_expect_success 'no warning with sendemail.chainreplyto = true' '
852852
! grep "no-chain-reply-to" errors
853853
'
854854

855+
test_expect_success 'sendemail.to works' '
856+
git config --replace-all sendemail.to "Somebody <[email protected]>" &&
857+
git send-email \
858+
--dry-run \
859+
--from="Example <[email protected]>" \
860+
$patches $patches >stdout &&
861+
grep "To: Somebody <[email protected]>" stdout
862+
'
863+
864+
test_expect_success '--no-to overrides sendemail.to' '
865+
git send-email \
866+
--dry-run \
867+
--from="Example <[email protected]>" \
868+
--no-to \
869+
870+
$patches $patches >stdout &&
871+
grep "To: [email protected]" stdout &&
872+
! grep "To: Somebody <[email protected]>" stdout
873+
'
874+
875+
test_expect_success 'sendemail.cc works' '
876+
git config --replace-all sendemail.cc "Somebody <[email protected]>" &&
877+
git send-email \
878+
--dry-run \
879+
--from="Example <[email protected]>" \
880+
881+
$patches $patches >stdout &&
882+
grep "Cc: Somebody <[email protected]>" stdout
883+
'
884+
885+
test_expect_success '--no-cc overrides sendemail.cc' '
886+
git send-email \
887+
--dry-run \
888+
--from="Example <[email protected]>" \
889+
--no-cc \
890+
891+
892+
$patches $patches >stdout &&
893+
grep "Cc: [email protected]" stdout &&
894+
! grep "Cc: Somebody <[email protected]>" stdout
895+
'
896+
897+
test_expect_success 'sendemail.bcc works' '
898+
git config --replace-all sendemail.bcc "Other <[email protected]>" &&
899+
git send-email \
900+
--dry-run \
901+
--from="Example <[email protected]>" \
902+
903+
--smtp-server relay.example.com \
904+
$patches $patches >stdout &&
905+
grep "RCPT TO:<[email protected]>" stdout
906+
'
907+
908+
test_expect_success '--no-bcc overrides sendemail.bcc' '
909+
git send-email \
910+
--dry-run \
911+
--from="Example <[email protected]>" \
912+
--no-bcc \
913+
914+
915+
--smtp-server relay.example.com \
916+
$patches $patches >stdout &&
917+
grep "RCPT TO:<[email protected]>" stdout &&
918+
! grep "RCPT TO:<[email protected]>" stdout
919+
'
920+
855921
test_done

0 commit comments

Comments
 (0)