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 <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stephen Boyd committed
Mar 7, 2010 at 14:46 UTC
f434c083a097bdc43991e4b0282b9aa1a994a60e
2 files changed
+76
-4
git-send-email.perl
+10
-4
@@ -47,9 +47,9 @@ git send-email [options] <file | directory | rev-list options >
47
48
Composing:
49
--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:
53
--subject <str> * Email "Subject:"
54
--in-reply-to <str> * Email "In-Reply-To:"
55
--annotate * Review each patch that will be sent in an editor.
@@ -135,7 +135,7 @@ sub unique_email_list(@);
135
sub cleanup_compose_files();
136
137
# 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,
139
$initial_reply_to,$initial_subject,@files,
140
$author,$sender,$smtp_authpass,$annotate,$compose,$time);
141
@@ -261,8 +261,11 @@ my $rc = GetOptions("sender|from=s" => \$sender,
261
"in-reply-to=s" => \$initial_reply_to,
262
"subject=s" => \$initial_subject,
263
"to=s" => \@to,
264
+ "no-to" => \$no_to,
265
"cc=s" => \@initial_cc,
266
+ "no-cc" => \$no_cc,
267
"bcc=s" => \@bcclist,
268
+ "no-bcc" => \$no_bcc,
269
"chain-reply-to!" => \$chain_reply_to,
270
"smtp-server=s" => \$smtp_server,
271
"smtp-server-port=s" => \$smtp_server_port,
@@ -305,6 +308,9 @@ sub read_config {
308
309
foreach my $setting (keys %config_settings) {
310
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;
314
if (ref($target) eq "ARRAY") {
315
unless (@$target) {
316
my @values = Git::config(@repo, "$prefix.$setting");
t/t9001-send-email.sh
+66
@@ -852,4 +852,70 @@ test_expect_success 'no warning with sendemail.chainreplyto = true' '
852
! grep "no-chain-reply-to" errors
853
'
854
855
+test_expect_success 'sendemail.to works' '
856
+ git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
857
+ git send-email \
858
+ --dry-run \
859
+ --from="Example <nobody@example.com>" \
860
+ $patches $patches >stdout &&
861
+ grep "To: Somebody <somebody@ex.com>" stdout
862
+'
863
+
864
+test_expect_success '--no-to overrides sendemail.to' '
865
+ git send-email \
866
+ --dry-run \
867
+ --from="Example <nobody@example.com>" \
868
+ --no-to \
869
+ --to=nobody@example.com \
870
+ $patches $patches >stdout &&
871
+ grep "To: nobody@example.com" stdout &&
872
+ ! grep "To: Somebody <somebody@ex.com>" stdout
873
+'
874
+
875
+test_expect_success 'sendemail.cc works' '
876
+ git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
877
+ git send-email \
878
+ --dry-run \
879
+ --from="Example <nobody@example.com>" \
880
+ --to=nobody@example.com \
881
+ $patches $patches >stdout &&
882
+ grep "Cc: Somebody <somebody@ex.com>" stdout
883
+'
884
+
885
+test_expect_success '--no-cc overrides sendemail.cc' '
886
+ git send-email \
887
+ --dry-run \
888
+ --from="Example <nobody@example.com>" \
889
+ --no-cc \
890
+ --cc=bodies@example.com \
891
+ --to=nobody@example.com \
892
+ $patches $patches >stdout &&
893
+ grep "Cc: bodies@example.com" stdout &&
894
+ ! grep "Cc: Somebody <somebody@ex.com>" stdout
895
+'
896
+
897
+test_expect_success 'sendemail.bcc works' '
898
+ git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
899
+ git send-email \
900
+ --dry-run \
901
+ --from="Example <nobody@example.com>" \
902
+ --to=nobody@example.com \
903
+ --smtp-server relay.example.com \
904
+ $patches $patches >stdout &&
905
+ grep "RCPT TO:<other@ex.com>" stdout
906
+'
907
+
908
+test_expect_success '--no-bcc overrides sendemail.bcc' '
909
+ git send-email \
910
+ --dry-run \
911
+ --from="Example <nobody@example.com>" \
912
+ --no-bcc \
913
+ --bcc=bodies@example.com \
914
+ --to=nobody@example.com \
915
+ --smtp-server relay.example.com \
916
+ $patches $patches >stdout &&
917
+ grep "RCPT TO:<bodies@example.com>" stdout &&
918
+ ! grep "RCPT TO:<other@ex.com>" stdout
919
+'
920
+
921
test_done