[PATCHv2 3/3] send-email: add --no-cc, --no-to, and --no-bcc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 git-send-email.perl   |   14 +++++++---
 t/t9001-send-email.sh |   66 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index e05455f..d612ae8 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -47,9 +47,9 @@ git send-email [options] <file | directory | rev-list options >
 
   Composing:
     --from                  <str>  * Email From:
-    --to                    <str>  * Email To:
-    --cc                    <str>  * Email Cc:
-    --bcc                   <str>  * Email Bcc:
+    --[no-]to               <str>  * Email To:
+    --[no-]cc               <str>  * Email Cc:
+    --[no-]bcc              <str>  * Email Bcc:
     --subject               <str>  * Email "Subject:"
     --in-reply-to           <str>  * Email "In-Reply-To:"
     --annotate                     * Review each patch that will be sent in an editor.
@@ -135,7 +135,7 @@ sub unique_email_list(@);
 sub cleanup_compose_files();
 
 # Variables we fill in automatically, or via prompting:
-my (@to,@cc,@initial_cc,@bcclist,@xh,
+my (@to,$no_to,@cc,$no_cc,@initial_cc,@bcclist,$no_bcc,@xh,
 	$initial_reply_to,$initial_subject,@files,
 	$author,$sender,$smtp_authpass,$annotate,$compose,$time);
 
@@ -261,8 +261,11 @@ my $rc = GetOptions("sender|from=s" => \$sender,
                     "in-reply-to=s" => \$initial_reply_to,
 		    "subject=s" => \$initial_subject,
 		    "to=s" => \@to,
+		    "no-to" => \$no_to,
 		    "cc=s" => \@initial_cc,
+		    "no-cc" => \$no_cc,
 		    "bcc=s" => \@bcclist,
+		    "no-bcc" => \$no_bcc,
 		    "chain-reply-to!" => \$chain_reply_to,
 		    "smtp-server=s" => \$smtp_server,
 		    "smtp-server-port=s" => \$smtp_server_port,
@@ -305,6 +308,9 @@ sub read_config {
 
 	foreach my $setting (keys %config_settings) {
 		my $target = $config_settings{$setting};
+		next if $setting eq "to" and defined $no_to;
+		next if $setting eq "cc" and defined $no_cc;
+		next if $setting eq "bcc" and defined $no_bcc;
 		if (ref($target) eq "ARRAY") {
 			unless (@$target) {
 				my @values = Git::config(@repo, "$prefix.$setting");
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index c09f375..640b3d2 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -852,4 +852,70 @@ test_expect_success 'no warning with sendemail.chainreplyto = true' '
 	! grep "no-chain-reply-to" errors
 '
 
+test_expect_success 'sendemail.to works' '
+	git config --replace-all sendemail.to "Somebody <somebody@xxxxxx>" &&
+	git send-email \
+		--dry-run \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		$patches $patches >stdout &&
+	grep "To: Somebody <somebody@xxxxxx>" stdout
+'
+
+test_expect_success '--no-to overrides sendemail.to' '
+	git send-email \
+		--dry-run \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		--no-to \
+		--to=nobody@xxxxxxxxxxx \
+		$patches $patches >stdout &&
+	grep "To: nobody@xxxxxxxxxxx" stdout &&
+	! grep "To: Somebody <somebody@xxxxxx>" stdout
+'
+
+test_expect_success 'sendemail.cc works' '
+	git config --replace-all sendemail.cc "Somebody <somebody@xxxxxx>" &&
+	git send-email \
+		--dry-run \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		--to=nobody@xxxxxxxxxxx \
+		$patches $patches >stdout &&
+	grep "Cc: Somebody <somebody@xxxxxx>" stdout
+'
+
+test_expect_success '--no-cc overrides sendemail.cc' '
+	git send-email \
+		--dry-run \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		--no-cc \
+		--cc=bodies@xxxxxxxxxxx \
+		--to=nobody@xxxxxxxxxxx \
+		$patches $patches >stdout &&
+	grep "Cc: bodies@xxxxxxxxxxx" stdout &&
+	! grep "Cc: Somebody <somebody@xxxxxx>" stdout
+'
+
+test_expect_success 'sendemail.bcc works' '
+	git config --replace-all sendemail.bcc "Other <other@xxxxxx>" &&
+	git send-email \
+		--dry-run \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		--to=nobody@xxxxxxxxxxx \
+		--smtp-server relay.example.com \
+		$patches $patches >stdout &&
+	grep "RCPT TO:<other@xxxxxx>" stdout
+'
+
+test_expect_success '--no-bcc overrides sendemail.bcc' '
+	git send-email \
+		--dry-run \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		--no-bcc \
+		--bcc=bodies@xxxxxxxxxxx \
+		--to=nobody@xxxxxxxxxxx \
+		--smtp-server relay.example.com \
+		$patches $patches >stdout &&
+	grep "RCPT TO:<bodies@xxxxxxxxxxx>" stdout &&
+	! grep "RCPT TO:<other@xxxxxx>" stdout
+'
+
 test_done
-- 
1.7.0.1.171.geb5ee

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]