Skip to content

Commit 17b7a83

Browse files
jacob-kellerpeff
authored andcommitted
sendemail: teach git-send-email to dump alias names
Add an option "--dump-aliases" which changes the default behavior of git-send-email. This mode will simply read the alias files configured by sendemail.aliasesfile and sendemail.aliasfiletype and dump a list of all configured aliases, one per line. The intended use case for this option is the bash-completion script which will use it to autocomplete aliases on the options which take addresses. Add some tests for the new option using various alias file formats. A possible future extension to the alias dump format could be done by extending the --dump-aliases to take an optional argument defining the format to display. This has not been done in this patch as no user of this information has been identified. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 0c83680 commit 17b7a83

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

Documentation/git-send-email.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git send-email' [options] <file|directory|rev-list options>...
13+
'git send-email' --dump-aliases
1314

1415

1516
DESCRIPTION
@@ -387,6 +388,16 @@ default to '--validate'.
387388
Send emails even if safety checks would prevent it.
388389

389390

391+
Information
392+
~~~~~~~~~~~
393+
394+
--dump-aliases::
395+
Instead of the normal operation, dump the shorthand alias names from
396+
the configured alias file(s), one per line in alphabetical order. Note,
397+
this only includes the alias name and not its expanded email addresses.
398+
See 'sendemail.aliasesfile' for more information about aliases.
399+
400+
390401
CONFIGURATION
391402
-------------
392403

git-send-email.perl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ package main;
4646
sub usage {
4747
print <<EOT;
4848
git send-email [options] <file | directory | rev-list options >
49+
git send-email --dump-aliases
4950
5051
Composing:
5152
--from <str> * Email From:
@@ -101,6 +102,9 @@ sub usage {
101102
`git format-patch` ones.
102103
--force * Send even if safety checks would prevent it.
103104
105+
Information:
106+
--dump-aliases * Dump configured aliases and exit.
107+
104108
EOT
105109
exit(1);
106110
}
@@ -180,6 +184,7 @@ sub format_2822_time {
180184
my $format_patch;
181185
my $compose_filename;
182186
my $force = 0;
187+
my $dump_aliases = 0;
183188

184189
# Handle interactive edition of files.
185190
my $multiedit;
@@ -291,6 +296,11 @@ sub signal_handler {
291296

292297
my $help;
293298
my $rc = GetOptions("h" => \$help,
299+
"dump-aliases" => \$dump_aliases);
300+
usage() unless $rc;
301+
die "--dump-aliases incompatible with other options\n"
302+
if !$help and $dump_aliases and @ARGV;
303+
$rc = GetOptions(
294304
"sender|from=s" => \$sender,
295305
"in-reply-to=s" => \$initial_reply_to,
296306
"subject=s" => \$initial_subject,
@@ -551,6 +561,11 @@ sub parse_sendmail_aliases {
551561
}
552562
}
553563

564+
if ($dump_aliases) {
565+
print "$_\n" for (sort keys %aliases);
566+
exit(0);
567+
}
568+
554569
# is_format_patch_arg($f) returns 0 if $f names a patch, or 1 if
555570
# $f is a revision list specification to be passed to format-patch.
556571
sub is_format_patch_arg {

t/t9001-send-email.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,88 @@ test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
15551555
grep "^!someone@example\.org!$" commandline1
15561556
'
15571557

1558+
test_dump_aliases () {
1559+
msg="$1" && shift &&
1560+
filetype="$1" && shift &&
1561+
printf '%s\n' "$@" >expect &&
1562+
cat >.tmp-email-aliases &&
1563+
1564+
test_expect_success $PREREQ "$msg" '
1565+
clean_fake_sendmail && rm -fr outdir &&
1566+
git config --replace-all sendemail.aliasesfile \
1567+
"$(pwd)/.tmp-email-aliases" &&
1568+
git config sendemail.aliasfiletype "$filetype" &&
1569+
git send-email --dump-aliases 2>errors >actual &&
1570+
test_cmp expect actual
1571+
'
1572+
}
1573+
1574+
test_dump_aliases '--dump-aliases sendmail format' \
1575+
'sendmail' \
1576+
'abgroup' \
1577+
'alice' \
1578+
'bcgrp' \
1579+
'bob' \
1580+
'chloe' <<-\EOF
1581+
alice: Alice W Land <[email protected]>
1582+
bob: Robert Bobbyton <[email protected]>
1583+
1584+
abgroup: alice, bob
1585+
bcgrp: bob, chloe, Other <[email protected]>
1586+
EOF
1587+
1588+
test_dump_aliases '--dump-aliases mutt format' \
1589+
'mutt' \
1590+
'alice' \
1591+
'bob' \
1592+
'chloe' \
1593+
'donald' <<-\EOF
1594+
alias alice Alice W Land <[email protected]>
1595+
alias donald Donald C Carlton <[email protected]>
1596+
alias bob Robert Bobbyton <[email protected]>
1597+
alias chloe [email protected]
1598+
EOF
1599+
1600+
test_dump_aliases '--dump-aliases mailrc format' \
1601+
'mailrc' \
1602+
'alice' \
1603+
'bob' \
1604+
'chloe' \
1605+
'eve' <<-\EOF
1606+
alias alice Alice W Land <[email protected]>
1607+
alias eve Eve <[email protected]>
1608+
alias bob Robert Bobbyton <[email protected]>
1609+
alias chloe [email protected]
1610+
EOF
1611+
1612+
test_dump_aliases '--dump-aliases pine format' \
1613+
'pine' \
1614+
'alice' \
1615+
'bob' \
1616+
'chloe' \
1617+
'eve' <<-\EOF
1618+
alice Alice W Land <[email protected]>
1619+
1620+
bob Robert Bobbyton <[email protected]>
1621+
1622+
EOF
1623+
1624+
test_dump_aliases '--dump-aliases gnus format' \
1625+
'gnus' \
1626+
'alice' \
1627+
'bob' \
1628+
'chloe' \
1629+
'eve' <<-\EOF
1630+
(define-mail-alias "alice" "[email protected]")
1631+
(define-mail-alias "eve" "[email protected]")
1632+
(define-mail-alias "bob" "[email protected]")
1633+
(define-mail-alias "chloe" "[email protected]")
1634+
EOF
1635+
1636+
test_expect_success '--dump-aliases must be used alone' '
1637+
test_must_fail git send-email --dump-aliases [email protected] -1 refs/heads/accounting
1638+
'
1639+
15581640
test_sendmail_aliases () {
15591641
msg="$1" && shift &&
15601642
expect="$@" &&

0 commit comments

Comments
 (0)