git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 2/7] send-email: allow aliases in patch header and command script outputs

From
Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
Date
Jun 9, 2015, 17:56 UTC
Message-ID
<1433872587-15515-3-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
In-Reply-To
<1433872587-15515-1-git-send-email-remi.lespinet@ensimag.grenoble-inp.fr>
Interpret aliases in:
  -  Header fields of patches generated by git format-patch
     (using --to, --cc, --add-header for example) or
     manually modified. Example of fields in header:
      To: alias1
      Cc: alias2
      Cc: alias3
  -  Outputs of command scripts specified by --cc-cmd and
     --to-cmd. Example of script:
      #!/bin/sh
      echo alias1
      echo alias2
--

Note that the --from option of git format-patch takes an argument which must be formated as .*<.*> (if not, git format-patch will be aborted with fatal: invalid ident line). For this reason, passing an alias as an argument of --from is not possible, but modifying the from field in the patch manually is.

Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
 git-send-email.perl   |  2 ++
 t/t9001-send-email.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
diff --git a/git-send-email.perl b/git-send-email.perl
index e1e9b14..0cac4b0 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1535,7 +1535,9 @@ foreach my $t (@files) {
 		($confirm =~ /^(?:auto|compose)$/ && $compose && $message_num == 1));
 	$needs_confirm = "inform" if ($needs_confirm && $confirm_unconfigured && @cc);
 
+	@to = expand_aliases(@to);
 	@to = validate_address_list(sanitize_address_list(@to));
+	@cc = expand_aliases(@cc);
 	@cc = validate_address_list(sanitize_address_list(@cc));
 
 	@to = (@initial_to, @to);
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index e63fc83..062c703 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1552,6 +1552,66 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
 	grep "^!someone@example\.org!$" commandline1
 '
 
+test_expect_success $PREREQ 'alias support in To header' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 --to=sbd >aliased.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		aliased.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'alias support in Cc header' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 --cc=sbd >aliased.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		aliased.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'tocmd works with aliases' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 >tocmd.patch &&
+	echo tocmd--sbd >>tocmd.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to-cmd=./tocmd-sed \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		tocmd.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
+test_expect_success $PREREQ 'cccmd works with aliases' '
+	clean_fake_sendmail &&
+	echo "alias sbd  someone@example.org" >.mailrc &&
+	test_config sendemail.aliasesfile ".mailrc" &&
+	test_config sendemail.aliasfiletype mailrc &&
+	git format-patch --stdout -1 >cccmd.patch &&
+	echo cccmd--sbd >>cccmd.patch &&
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--cc-cmd=./cccmd-sed \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		cccmd.patch \
+		2>errors >out &&
+	grep "^!someone@example\.org!$" commandline1
+'
+
 do_xmailer_test () {
 	expected=$1 params=$2 &&
 	git format-patch -1 &&
-- 
1.9.1
Previous: Remi LespinetNext: Remi Lespinet
Message 3 of 8 in “changes from last version”
  1. 0/7 changes from last versionRemi Lespinet, Jun 9, 2015
  2. 1/7 t9001-send-email: move script creation in a setup testRemi Lespinet, Jun 9, 2015
  3. 2/7 send-email: allow aliases in patch header and command script outputsRemi Lespinet, Jun 9, 2015
  4. 3/7 t9001-send-email: refactor header variable fields replacementRemi Lespinet, Jun 9, 2015
  5. 4/7 send-email: refactor address list processRemi Lespinet, Jun 9, 2015
  6. 5/7 send-email: allow multiple emails using --cc, --to and --bccRemi Lespinet, Jun 9, 2015
  7. Junio C HamanoJun 10, 2015
  8. Matthieu MoyJun 10, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.