send-email: Fix %config_path_settings handling

cec5dae (use new Git::config_path() for aliasesfile, 2011-09-30) broke
the expansion of aliases.

This was caused by treating %config_path_settings, newly introduced in
said patch, like %config_bool_settings instead of like %config_settings.
Copy from %config_settings, making it more readable.

While at it add basic test for expansion of aliases, and for path
expansion, which would catch this error.

Nb. there were a few issues that were responsible for this error:

1. %config_bool_settings and %config_settings despite similar name have
   different semantic.

   %config_bool_settings values are arrays where the first element is
   (reference to) the variable to set, and second element is default
   value... which admittedly is a bit cryptic.  More readable if more
   verbose option would be to use hash reference, e.g.:

        my %config_bool_settings = (
            "thread" => { variable => \$thread, default => 1},
            [...]

   %config_settings values are either either reference to scalar variable
   or reference to array.  In second case it means that option (or config
   option) is multi-valued.  BTW. this is similar to what Getopt::Long does.

2. In cec5dae (use new Git::config_path() for aliasesfile, 2011-09-30)
   the setting "aliasesfile" was moved from %config_settings to newly
   introduced %config_path_settings.  But the loop that parses settings
   from %config_path_settings was copy'n'pasted *wrongly* from
   %config_bool_settings instead of from %config_settings.

   It looks like cec5dae author cargo-culted this change...

3. 994d6c6 (send-email: address expansion for common mailers, 2006-05-14)
   didn't add test for alias expansion to t9001-send-email.sh

Signed-off-by: Cord Seele <cowose@gmail.com>
Tested-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Cord Seele 2011-10-14 22:53:31 +02:00 коммит произвёл Junio C Hamano
Родитель cf8ddeead9
Коммит 463b0ea22b
2 изменённых файлов: 38 добавлений и 2 удалений

Просмотреть файл

@ -337,9 +337,17 @@ sub read_config {
}
foreach my $setting (keys %config_path_settings) {
my $target = $config_path_settings{$setting}->[0];
my $target = $config_path_settings{$setting};
if (ref($target) eq "ARRAY") {
unless (@$target) {
my @values = Git::config_path(@repo, "$prefix.$setting");
@$target = @values if (@values && defined $values[0]);
}
}
else {
$$target = Git::config_path(@repo, "$prefix.$setting") unless (defined $$target);
}
}
foreach my $setting (keys %config_settings) {
my $target = $config_settings{$setting};

Просмотреть файл

@ -1168,4 +1168,32 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' '
test -n "$(ls msgtxt*)"
'
test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
clean_fake_sendmail &&
echo "alias sbd somebody@example.org" >.mailrc &&
git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
git config sendemail.aliasfiletype mailrc &&
git send-email \
--from="Example <nobody@example.com>" \
--to=sbd \
--smtp-server="$(pwd)/fake.sendmail" \
outdir/0001-*.patch \
2>errors >out &&
grep "^!somebody@example\.org!$" commandline1
'
test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
clean_fake_sendmail &&
echo "alias sbd someone@example.org" >~/.mailrc &&
git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
git config sendemail.aliasfiletype mailrc &&
git send-email \
--from="Example <nobody@example.com>" \
--to=sbd \
--smtp-server="$(pwd)/fake.sendmail" \
outdir/0001-*.patch \
2>errors >out &&
grep "^!someone@example\.org!$" commandline1
'
test_done