Merge branch 'jk/send-email-translate-aliases'
"git send-email" learned "--translate-aliases" option that reads addresses from the standard input and emits the result of applying aliases on them to the standard output. * jk/send-email-translate-aliases: send-email: teach git send-email option to translate aliases t9001-send-email.sh: update alias list used for pine test t9001-send-email.sh: fix quoting for mailrc --dump-aliases testmaint
commit
3dd2a2feca
|
@ -12,6 +12,7 @@ SYNOPSIS
|
|||
'git send-email' [<options>] (<file>|<directory>)...
|
||||
'git send-email' [<options>] <format-patch-options>
|
||||
'git send-email' --dump-aliases
|
||||
'git send-email' --translate-aliases
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
|
@ -475,6 +476,12 @@ Information
|
|||
that this only includes the alias name and not its expanded email addresses.
|
||||
See 'sendemail.aliasesFile' for more information about aliases.
|
||||
|
||||
--translate-aliases::
|
||||
Instead of the normal operation, read from standard input and
|
||||
interpret each line as an email alias. Translate it according to the
|
||||
configured alias file(s). Output each translated name and email
|
||||
address to standard output, one per line. See 'sendemail.aliasFile'
|
||||
for more information about aliases.
|
||||
|
||||
CONFIGURATION
|
||||
-------------
|
||||
|
|
|
@ -31,6 +31,7 @@ sub usage {
|
|||
git send-email [<options>] <file|directory>
|
||||
git send-email [<options>] <format-patch options>
|
||||
git send-email --dump-aliases
|
||||
git send-email --translate-aliases
|
||||
|
||||
Composing:
|
||||
--from <str> * Email From:
|
||||
|
@ -99,6 +100,10 @@ git send-email --dump-aliases
|
|||
|
||||
Information:
|
||||
--dump-aliases * Dump configured aliases and exit.
|
||||
--translate-aliases * Translate aliases read from standard
|
||||
input according to the configured email
|
||||
alias file(s), outputting the result to
|
||||
standard output.
|
||||
|
||||
EOT
|
||||
exit(1);
|
||||
|
@ -212,6 +217,7 @@ my $format_patch;
|
|||
my $compose_filename;
|
||||
my $force = 0;
|
||||
my $dump_aliases = 0;
|
||||
my $translate_aliases = 0;
|
||||
|
||||
# Variables to prevent short format-patch options from being captured
|
||||
# as abbreviated send-email options
|
||||
|
@ -476,11 +482,14 @@ my $git_completion_helper;
|
|||
my %dump_aliases_options = (
|
||||
"h" => \$help,
|
||||
"dump-aliases" => \$dump_aliases,
|
||||
"translate-aliases" => \$translate_aliases,
|
||||
);
|
||||
$rc = GetOptions(%dump_aliases_options);
|
||||
usage() unless $rc;
|
||||
die __("--dump-aliases incompatible with other options\n")
|
||||
if !$help and $dump_aliases and @ARGV;
|
||||
if !$help and ($dump_aliases or $translate_aliases) and @ARGV;
|
||||
die __("--dump-aliases and --translate-aliases are mutually exclusive\n")
|
||||
if !$help and $dump_aliases and $translate_aliases;
|
||||
my %options = (
|
||||
"sender|from=s" => \$sender,
|
||||
"in-reply-to=s" => \$initial_in_reply_to,
|
||||
|
@ -724,6 +733,16 @@ if ($dump_aliases) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
if ($translate_aliases) {
|
||||
while (<STDIN>) {
|
||||
my @addr_list = parse_address_line($_);
|
||||
@addr_list = expand_aliases(@addr_list);
|
||||
@addr_list = sanitize_address_list(@addr_list);
|
||||
print "$_\n" for @addr_list;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
# is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if
|
||||
# $f is a revision list specification to be passed to format-patch.
|
||||
sub is_format_patch_arg {
|
||||
|
|
|
@ -2084,22 +2084,24 @@ test_dump_aliases '--dump-aliases mailrc format' \
|
|||
'bob' \
|
||||
'chloe' \
|
||||
'eve' <<-\EOF
|
||||
alias alice Alice W Land <awol@example.com>
|
||||
alias eve Eve <eve@example.com>
|
||||
alias bob Robert Bobbyton <bob@example.com>
|
||||
alias alice "Alice W Land <awol@example.com>"
|
||||
alias eve "Eve <eve@example.com>"
|
||||
alias bob "Robert Bobbyton <bob@example.com>"
|
||||
alias chloe chloe@example.com
|
||||
EOF
|
||||
|
||||
test_dump_aliases '--dump-aliases pine format' \
|
||||
'pine' \
|
||||
'alice' \
|
||||
'bcgrp' \
|
||||
'bob' \
|
||||
'chloe' \
|
||||
'eve' <<-\EOF
|
||||
alice Alice W Land <awol@example.com>
|
||||
eve Eve <eve@example.com>
|
||||
bob Robert Bobbyton <bob@example.com>
|
||||
alice Alice W Land awol@example.com Friend
|
||||
eve Eve eve@example.com
|
||||
bob Robert Bobbyton bob@example.com
|
||||
chloe chloe@example.com
|
||||
bcgrp (bob, chloe, Other <o@example.com>)
|
||||
EOF
|
||||
|
||||
test_dump_aliases '--dump-aliases gnus format' \
|
||||
|
@ -2118,6 +2120,110 @@ test_expect_success '--dump-aliases must be used alone' '
|
|||
test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
|
||||
'
|
||||
|
||||
test_translate_aliases () {
|
||||
msg="$1" && shift &&
|
||||
filetype="$1" && shift &&
|
||||
aliases="$1" && shift &&
|
||||
printf '%s\n' "$@" >expect &&
|
||||
cat >.tmp-email-aliases &&
|
||||
printf '%s\n' "$aliases" >aliases &&
|
||||
|
||||
test_expect_success $PREREQ "$msg" '
|
||||
clean_fake_sendmail && rm -fr outdir &&
|
||||
git config --replace-all sendemail.aliasesfile \
|
||||
"$(pwd)/.tmp-email-aliases" &&
|
||||
git config sendemail.aliasfiletype "$filetype" &&
|
||||
git send-email --translate-aliases <aliases 2>errors >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
}
|
||||
|
||||
test_translate_aliases '--translate-aliases sendmail format' \
|
||||
'sendmail' \
|
||||
'alice bcgrp' \
|
||||
'Alice W Land <awol@example.com>' \
|
||||
'Robert Bobbyton <bob@example.com>' \
|
||||
'chloe@example.com' \
|
||||
'Other <o@example.com>' <<-\EOF
|
||||
alice: Alice W Land <awol@example.com>
|
||||
bob: Robert Bobbyton <bob@example.com>
|
||||
chloe: chloe@example.com
|
||||
abgroup: alice, bob
|
||||
bcgrp: bob, chloe, Other <o@example.com>
|
||||
EOF
|
||||
|
||||
test_translate_aliases '--translate-aliases mutt format' \
|
||||
'mutt' \
|
||||
'donald bob' \
|
||||
'Donald C Carlton <donc@example.com>' \
|
||||
'Robert Bobbyton <bob@example.com>' <<-\EOF
|
||||
alias alice Alice W Land <awol@example.com>
|
||||
alias donald Donald C Carlton <donc@example.com>
|
||||
alias bob Robert Bobbyton <bob@example.com>
|
||||
alias chloe chloe@example.com
|
||||
EOF
|
||||
|
||||
test_translate_aliases '--translate-aliases mailrc format' \
|
||||
'mailrc' \
|
||||
'chloe eve alice' \
|
||||
'chloe@example.com' \
|
||||
'Eve <eve@example.com>' \
|
||||
'Alice W Land <awol@example.com>' <<-\EOF
|
||||
alias alice "Alice W Land <awol@example.com>"
|
||||
alias eve "Eve <eve@example.com>"
|
||||
alias bob "Robert Bobbyton <bob@example.com>"
|
||||
alias chloe chloe@example.com
|
||||
EOF
|
||||
|
||||
test_translate_aliases '--translate-aliases pine format' \
|
||||
'pine' \
|
||||
'eve bob bcgrp' \
|
||||
'eve@example.com' \
|
||||
'bob@example.com' \
|
||||
'bob@example.com' \
|
||||
'chloe@example.com' \
|
||||
'Other <o@example.com>' <<-\EOF
|
||||
alice Alice W Land awol@example.com Friend
|
||||
eve Eve eve@example.com
|
||||
bob Robert Bobbyton bob@example.com
|
||||
chloe chloe@example.com
|
||||
bcgrp (bob, chloe, Other <o@example.com>)
|
||||
EOF
|
||||
|
||||
test_translate_aliases '--translate-aliases gnus format' \
|
||||
'gnus' \
|
||||
'alice chloe eve' \
|
||||
'awol@example.com' \
|
||||
'chloe@example.com' \
|
||||
'eve@example.com' <<-\EOF
|
||||
(define-mail-alias "alice" "awol@example.com")
|
||||
(define-mail-alias "eve" "eve@example.com")
|
||||
(define-mail-alias "bob" "bob@example.com")
|
||||
(define-mail-alias "chloe" "chloe@example.com")
|
||||
EOF
|
||||
|
||||
test_expect_success $PREREQ '--translate-aliases passes valid addresses through' '
|
||||
cat >expect <<-\EOF &&
|
||||
Other <o@example.com>
|
||||
EOF
|
||||
cat >aliases <<-\EOF &&
|
||||
Other <o@example.com>
|
||||
EOF
|
||||
git send-email --translate-aliases <aliases >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ '--translate-aliases passes unknown aliases through' '
|
||||
cat >expect <<-\EOF &&
|
||||
blargh
|
||||
EOF
|
||||
cat >aliases <<-\EOF &&
|
||||
blargh
|
||||
EOF
|
||||
git send-email --translate-aliases <aliases >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success $PREREQ 'aliases and sendemail.identity' '
|
||||
test_must_fail git \
|
||||
-c sendemail.identity=cloud \
|
||||
|
|
Loading…
Reference in New Issue